From 3116116e68b53bd1a558b3cc431197f330c299b2 Mon Sep 17 00:00:00 2001 From: Anton Gladky Date: Fri, 17 Sep 2021 21:54:52 +0200 Subject: [PATCH] New upstream version 9.0.3+dfsg1 --- .kitware-release.json | 10 + CMake/CTestCustom.cmake.in | 6 + CMake/setup.py.in | 74 +- CMake/vtkVersion.cmake | 2 +- CMake/vtkWheelFinalization.cmake | 4 + CMake/vtkWheelPreparation.cmake | 20 +- CMakeLists.txt | 28 +- Common/Core/Testing/Cxx/CMakeLists.txt | 1 + .../Testing/Cxx/TestAbstractArraySize.cxx | 61 ++ Common/Core/vtkAbstractArray.cxx | 8 +- Common/Core/vtkSetGet.h | 28 + Common/Core/vtkStringArray.cxx | 2 +- Documentation/release/9.0.md | 71 ++ ...ring-change-for-VTK_LAGRANGE_HEXAHEDRON.md | 28 - Documentation/release/dev/pegtl.md | 3 - Domains/ChemistryOpenGL2/vtk.module | 2 + Examples/GUI/Cocoa/CustomLayer.mm | 4 +- Examples/GUI/Cocoa/MyWindowController.mm | 9 + Filters/Core/vtk3DLinearGridPlaneCutter.cxx | 12 +- Filters/Core/vtkCutter.cxx | 3 + Filters/Sources/Testing/Cxx/CMakeLists.txt | 1 + .../Sources/Testing/Cxx/TestArrowSource.cxx | 149 +++ .../Data/Baseline/TestArrowSource.png.sha512 | 1 + Filters/Sources/vtkArrowSource.cxx | 53 +- Filters/Sources/vtkArrowSource.h | 20 + Filters/Verdict/vtkMatrixMathFilter.cxx | 2 +- GUISupport/Qt/CMakeLists.txt | 1 + Imaging/Core/CMakeLists.txt | 1 + Imaging/Core/Testing/Cxx/CMakeLists.txt | 1 + .../Core/Testing/Cxx/TestImageProbeFilter.cxx | 251 +++++ .../Baseline/TestImageProbeFilter.png.sha512 | 1 + Imaging/Core/vtkImageFlip.cxx | 12 +- Imaging/Core/vtkImageProbeFilter.cxx | 400 +++++++ Imaging/Core/vtkImageProbeFilter.h | 126 +++ Imaging/Core/vtkImageResample.cxx | 2 +- Imaging/Core/vtkImageReslice.cxx | 21 +- Imaging/Core/vtkImageReslice.h | 7 + Parallel/Core/vtkPSystemTools.cxx | 4 +- Remote/vtkDICOM.remote.cmake | 4 +- Rendering/Annotation/vtkAxesActor.cxx | 64 +- Rendering/ContextOpenGL2/vtk.module | 2 + ...olyDataMapper2MixedGeometryCellScalars.cxx | 12 +- ...ositePolyDataMapper2MixedGeometryEdges.cxx | 12 +- .../TestCompositePolyDataMapper2.png.sha512 | 2 +- ...ositePolyDataMapper2CellScalars.png.sha512 | 2 +- ...Mapper2MixedGeometryCellScalars.png.sha512 | 2 +- ...lyDataMapper2MixedGeometryEdges.png.sha512 | 2 +- ...CompositePolyDataMapper2Picking.png.sha512 | 2 +- ...CompositePolyDataMapper2Scalars.png.sha512 | 2 +- .../vtkCompositeDataDisplayAttributes.cxx | 4 - Rendering/Core/vtkWindowLevelLookupTable.cxx | 53 +- Rendering/Core/vtkWindowLevelLookupTable.h | 2 +- Rendering/FreeType/vtkFreeTypeTools.cxx | 3 +- .../vtkFontConfigFreeTypeTools.cxx | 3 +- .../GL2PSOpenGL2/Testing/Cxx/CMakeLists.txt | 2 +- .../TestCompositePolyDataMapper2Spheres.cxx | 10 +- ...CompositePolyDataMapper2Spheres.png.sha512 | 2 +- ...mpositePolyDataMapper2Spheres_1.png.sha512 | 1 + ...ompositePolyDataMapper2Vertices.png.sha512 | 2 +- Rendering/OpenGL2/vtk.module | 2 + Rendering/OpenGL2/vtkCocoaGLView.mm | 5 + Rendering/OpenGL2/vtkCocoaRenderWindow.mm | 18 + Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx | 15 + ...tOSPRayCompositePolyDataMapper2.png.sha512 | 2 +- Rendering/RayTracing/vtkOSPRayPass.cxx | 91 ++ Rendering/RayTracing/vtkOSPRayPass.h | 5 + Rendering/RayTracing/vtkOSPRayWindowNode.cxx | 11 + ThirdParty/hdf5/update.sh | 8 +- Utilities/DICOMParser/DICOMParser.cxx | 4 +- Utilities/KWSys/vtksys/Base64.c | 5 +- Utilities/KWSys/vtksys/CMakeLists.txt | 121 +-- Utilities/KWSys/vtksys/CTestConfig.cmake | 4 +- .../KWSys/vtksys/CommandLineArguments.cxx | 6 +- Utilities/KWSys/vtksys/Configure.h.in | 8 - Utilities/KWSys/vtksys/Directory.cxx | 65 +- Utilities/KWSys/vtksys/Directory.hxx.in | 5 +- Utilities/KWSys/vtksys/DynamicLoader.cxx | 22 - Utilities/KWSys/vtksys/EncodingCXX.cxx | 4 +- Utilities/KWSys/vtksys/FStream.hxx.in | 46 + Utilities/KWSys/vtksys/Glob.cxx | 22 +- Utilities/KWSys/vtksys/Glob.hxx.in | 5 +- Utilities/KWSys/vtksys/IOStream.cxx | 255 ----- Utilities/KWSys/vtksys/IOStream.hxx.in | 126 --- Utilities/KWSys/vtksys/MD5.c | 30 +- Utilities/KWSys/vtksys/ProcessUNIX.c | 221 ++-- Utilities/KWSys/vtksys/ProcessWin32.c | 13 +- Utilities/KWSys/vtksys/RegularExpression.cxx | 9 +- .../KWSys/vtksys/RegularExpression.hxx.in | 6 - Utilities/KWSys/vtksys/SharedForward.h.in | 6 - Utilities/KWSys/vtksys/String.hxx.in | 8 - Utilities/KWSys/vtksys/SystemInformation.cxx | 541 ++++++---- .../KWSys/vtksys/SystemInformation.hxx.in | 21 +- Utilities/KWSys/vtksys/SystemTools.cxx | 227 ++-- Utilities/KWSys/vtksys/SystemTools.hxx.in | 36 +- Utilities/KWSys/vtksys/hash_fun.hxx.in | 166 --- Utilities/KWSys/vtksys/hash_map.hxx.in | 423 -------- Utilities/KWSys/vtksys/hash_set.hxx.in | 392 ------- Utilities/KWSys/vtksys/hashtable.hxx.in | 995 ------------------ Utilities/KWSys/vtksys/kwsysPlatformTestsC.c | 37 - .../KWSys/vtksys/kwsysPlatformTestsCXX.cxx | 161 --- .../KWSys/vtksys/testCommandLineArguments.cxx | 4 +- .../vtksys/testCommandLineArguments1.cxx | 8 +- Utilities/KWSys/vtksys/testDirectory.cxx | 37 +- Utilities/KWSys/vtksys/testDynload.c | 2 +- Utilities/KWSys/vtksys/testEncoding.cxx | 8 +- Utilities/KWSys/vtksys/testFStream.cxx | 43 +- Utilities/KWSys/vtksys/testHashSTL.cxx | 64 -- Utilities/KWSys/vtksys/testProcess.c | 28 +- .../KWSys/vtksys/testSystemInformation.cxx | 18 +- Utilities/KWSys/vtksys/testSystemTools.cxx | 91 +- Utilities/MPI/CMakeLists.txt | 1 + Utilities/MPI/vtk_mpi.h | 11 + Utilities/Maintenance/SourceTarball.bash | 2 +- .../vtkPythonInterpreter.cxx | 5 + .../Python/vtkmodules/util/numpy_support.py | 3 +- Wrapping/PythonCore/PyVTKMethodDescriptor.cxx | 2 +- Wrapping/PythonCore/vtkPythonCommand.cxx | 2 +- Wrapping/PythonCore/vtkPythonUtil.cxx | 4 +- 118 files changed, 2471 insertions(+), 3626 deletions(-) create mode 100644 .kitware-release.json create mode 100644 Common/Core/Testing/Cxx/TestAbstractArraySize.cxx create mode 100644 Documentation/release/9.0.md delete mode 100644 Documentation/release/dev/node-numbering-change-for-VTK_LAGRANGE_HEXAHEDRON.md delete mode 100644 Documentation/release/dev/pegtl.md create mode 100644 Filters/Sources/Testing/Cxx/TestArrowSource.cxx create mode 100644 Filters/Sources/Testing/Data/Baseline/TestArrowSource.png.sha512 create mode 100644 Imaging/Core/Testing/Cxx/TestImageProbeFilter.cxx create mode 100644 Imaging/Core/Testing/Data/Baseline/TestImageProbeFilter.png.sha512 create mode 100644 Imaging/Core/vtkImageProbeFilter.cxx create mode 100644 Imaging/Core/vtkImageProbeFilter.h create mode 100644 Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Spheres_1.png.sha512 delete mode 100644 Utilities/KWSys/vtksys/IOStream.cxx delete mode 100644 Utilities/KWSys/vtksys/IOStream.hxx.in delete mode 100644 Utilities/KWSys/vtksys/hash_fun.hxx.in delete mode 100644 Utilities/KWSys/vtksys/hash_map.hxx.in delete mode 100644 Utilities/KWSys/vtksys/hash_set.hxx.in delete mode 100644 Utilities/KWSys/vtksys/hashtable.hxx.in delete mode 100644 Utilities/KWSys/vtksys/testHashSTL.cxx diff --git a/.kitware-release.json b/.kitware-release.json new file mode 100644 index 000000000..b4da2258f --- /dev/null +++ b/.kitware-release.json @@ -0,0 +1,10 @@ +{ + "release_user": "kwrobot.release.vtk", + "project": "vtk/vtk", + "maintainers": [ + "ben.boeckel", + "ken-martin", + "utkarsh.ayachit", + "vbolea" + ] +} diff --git a/CMake/CTestCustom.cmake.in b/CMake/CTestCustom.cmake.in index 466284970..450d9e688 100644 --- a/CMake/CTestCustom.cmake.in +++ b/CMake/CTestCustom.cmake.in @@ -95,6 +95,12 @@ if (NOT cdash_show_third_party_warnings) # Suppress ThirdParty source code from displaying warnings. "[Tt]hird[Pp]arty" + # clang will often give multiline warnings from macro expansions, + # where the first part has "warning:" and subsequent parts have "note:" + # and those will sometimes expand into systems headers. When this occurs + # for ThirdParty code, we want it suppressed too. Do so here for headers within Xcode. + "Xcode\\.app/Contents/Developer.+note:" + # Suppress Remote module source code from displaying warnings. # Suppress modules individually as just "Remote" is a common pattern "[Rr]emote.[Mm]oment[Ii]nvariants" diff --git a/CMake/setup.py.in b/CMake/setup.py.in index ad0a5b9cc..fe7fa69f4 100644 --- a/CMake/setup.py.in +++ b/CMake/setup.py.in @@ -70,9 +70,75 @@ python_code_features = { features = python_code_features features.update(vtk_features.FEATURES) +extra_packages = [] +if 'web' in vtk_features.FEATURES: + extra_packages.append('vtkmodules.web') + +######################################## +# Version computation logic +######################################## + +# Assume a development version at first. +version_base = '@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@.@VTK_BUILD_VERSION@' +version = version_base + '.dev0' + +if 'GITLAB_CI' in os.environ: + if 'CI_COMMIT_TAG' in os.environ: + if '.rc' in os.environ['CI_COMMIT_TAG']: + # rc tag. Add this to the version. + rc_bit = os.environ['CI_COMMIT_TAG'].split('.')[-1] + version = version_base + '.' + rc_bit + else: + # Official release, use the version number. + version = version_base + elif 'CI_COMMIT_BRANCH' in os.environ: + # Build on an official branch. + + # Check if we're on `master` or the release branch. + if 20200000 < int('@VTK_BUILD_VERSION@'): + # Master, count commits since the last nightly update. + git_log = subprocess.Popen([ + 'git', + 'log', + '--first-parent', + '--pretty=%s', + os.environ['CI_COMMIT_BRANCH'], + ], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=os.environ['GIT_CLONE_PATH'], + ) + + count = 0 + for line in git_log.stdout.readlines(): + if line == b'VTK Nightly Date Stamp\n': + break + count += 1 + else: + # Release branch, count commits since the last tag. + git_log = subprocess.Popen([ + 'git', + 'log', + '--first-parent', + '--pretty=%s', + 'v' + version_base + '..' + ], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=os.environ['GIT_CLONE_PATH'], + ) + + count = len(git_log.stdout.readlines()) + + version = version_base + '.dev' + str(count) + elif 'CI_MERGE_REQUEST_ID' in os.environ: + # Build on a merge request. + version = version_base + '.dev0' + '+mr' + \ + os.environ['CI_MERGE_REQUEST_ID'] + setup( name='vtk', - version='@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@.@VTK_BUILD_VERSION@', + version=version, author='VTK developers', packages=[ 'vtkmodules', @@ -83,13 +149,13 @@ setup( 'vtkmodules.tk', 'vtkmodules.util', 'vtkmodules.wx', - ], + ] + extra_packages, py_modules=[ 'vtk', ], ext_package='vtkmodules', ext_modules=[ - # https://gitlab.kitware.com/cmake/cmake/issues/19145 + # https://gitlab.kitware.com/cmake/cmake/-/issues/19145 #ConfiguredCMakeExtension('vtkmodules', target='vtkpythonmodules'), ConfiguredCMakeExtension('vtkCommonCorePython', target='vtkCommonCorePython'), ], @@ -102,7 +168,7 @@ setup( # macOS modules. '*-darwin.so', # macOS shared libraries. - 'lib*.dylib*', + '.dylibs', # Windows modules. '*.pyd', # Windows shared libraries. diff --git a/CMake/vtkVersion.cmake b/CMake/vtkVersion.cmake index 8530c73bf..ebbed7501 100644 --- a/CMake/vtkVersion.cmake +++ b/CMake/vtkVersion.cmake @@ -1,7 +1,7 @@ # VTK version number components. set(VTK_MAJOR_VERSION 9) set(VTK_MINOR_VERSION 0) -set(VTK_BUILD_VERSION 1) +set(VTK_BUILD_VERSION 3) if (NOT VTK_MINOR_VERSION LESS 100) message(FATAL_ERROR diff --git a/CMake/vtkWheelFinalization.cmake b/CMake/vtkWheelFinalization.cmake index d20c41a57..3ac32fdca 100644 --- a/CMake/vtkWheelFinalization.cmake +++ b/CMake/vtkWheelFinalization.cmake @@ -1,5 +1,9 @@ set(vtk_features) +if (TARGET VTK::WebPython) + list(APPEND vtk_features "web") +endif () + if (TARGET VTK::mpi) list(APPEND vtk_features "mpi") endif () diff --git a/CMake/vtkWheelPreparation.cmake b/CMake/vtkWheelPreparation.cmake index 70eed7bbd..905deb881 100644 --- a/CMake/vtkWheelPreparation.cmake +++ b/CMake/vtkWheelPreparation.cmake @@ -1,6 +1,7 @@ # Force some VTK options for wheels. set(VTK_PYTHON_VERSION 3) set(VTK_BUILD_TESTING OFF) +set(VTK_LEGACY_SILENT ON) set(VTK_ENABLE_WRAPPING ON) set(VTK_WRAP_PYTHON ON) set(Python3_ARTIFACTS_INTERACTIVE ON) @@ -49,12 +50,19 @@ set(vtk_hierarchy_destination_args set(setup_py_build_dir "build/lib.${python_platform}-${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}") # Required for Windows DLL placement. -set(CMAKE_INSTALL_BINDIR - # Must correlate with `vtk_module_wrap_python(PYTHON_PACKAGE)` argument - "${setup_py_build_dir}/vtkmodules") -set(CMAKE_INSTALL_LIBDIR - # Must correlate with `vtk_module_wrap_python(PYTHON_PACKAGE)` argument - "${setup_py_build_dir}/vtkmodules") +if (WIN32) + set(CMAKE_INSTALL_BINDIR + # Must correlate with `vtk_module_wrap_python(PYTHON_PACKAGE)` argument + "${setup_py_build_dir}/vtkmodules") +elseif (APPLE) + set(CMAKE_INSTALL_LIBDIR + # Store libraries in a subdirectory here. + "${setup_py_build_dir}/vtkmodules/.dylibs") +else () + set(CMAKE_INSTALL_LIBDIR + # Linux bundles what libraries we have when they're put beside the modules. + "${setup_py_build_dir}/vtkmodules") +endif () set(VTK_PYTHON_SITE_PACKAGES_SUFFIX ".") set(VTK_CUSTOM_LIBRARY_SUFFIX "") set(VTK_INSTALL_SDK OFF) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00695601e..b5fd35035 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.8...3.12 FATAL_ERROR) foreach(policy CMP0083 # CMake 3.14 + CMP0077 # CMake 3.13 CMP0071 # CMake 3.10 CMP0068 # CMake 3.9 ) @@ -82,7 +83,9 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) #----------------------------------------------------------------------------- # Add the Remote Subdirectory -add_subdirectory(Remote) +if (VTK_ENABLE_REMOTE_MODULES) + add_subdirectory(Remote) +endif () #----------------------------------------------------------------------------- # Does VTK require support for 64 bit file systems @@ -329,6 +332,13 @@ if (VTK_CUSTOM_LIBRARY_SUFFIX STREQUAL "") endif () endif () +set(vtk_library_version_info + VERSION "${VTK_VERSION}" + SOVERSION "1") +if (VTK_WHEEL_BUILD) + set(vtk_library_version_info) +endif () + vtk_module_build( MODULES ${vtk_modules} KITS ${vtk_kits} @@ -339,8 +349,7 @@ vtk_module_build( CMAKE_DESTINATION "${vtk_cmake_destination}" LICENSE_DESTINATION "${CMAKE_INSTALL_LICENSEDIR}" LIBRARY_NAME_SUFFIX "${VTK_CUSTOM_LIBRARY_SUFFIX}" - VERSION "${VTK_VERSION}" - SOVERSION "1" + ${vtk_library_version_info} TEST_DATA_TARGET VTKData INSTALL_HEADERS "${VTK_INSTALL_SDK}" BUILD_WITH_KITS "${VTK_ENABLE_KITS}" @@ -370,6 +379,14 @@ if (VTK_WRAP_PYTHON) "${vtk_required_python_modules}\n") get_property(vtk_soabi GLOBAL PROPERTY _vtk_python_soabi) + + if (APPLE AND VTK_WHEEL_BUILD) + list(APPEND CMAKE_INSTALL_RPATH + # Wheels place loaded libraries under a `.dylibs` subdirectory. Add this + # to the rpath list. + "@loader_path/.dylibs") + endif () + vtk_module_wrap_python( MODULES ${vtk_modules} INSTALL_EXPORT VTKPython @@ -382,6 +399,11 @@ if (VTK_WRAP_PYTHON) WRAPPED_MODULES vtk_python_wrapped_modules TARGET VTK::vtkpythonmodules) + if (APPLE AND VTK_WHEEL_BUILD) + list(REMOVE_ITEM CMAKE_INSTALL_RPATH + "@loader_path/.dylibs") + endif () + add_subdirectory(Wrapping/Python) export( diff --git a/Common/Core/Testing/Cxx/CMakeLists.txt b/Common/Core/Testing/Cxx/CMakeLists.txt index 11bab0f54..72d27fd07 100644 --- a/Common/Core/Testing/Cxx/CMakeLists.txt +++ b/Common/Core/Testing/Cxx/CMakeLists.txt @@ -101,6 +101,7 @@ vtk_add_test_cxx(vtkCommonCoreCxxTests tests ExampleDataArrayRangeAPI.cxx ExampleDataArrayRangeDispatch.cxx UnitTestMath.cxx + TestAbstractArraySize.cxx TestArrayAPI.cxx TestArrayAPIConvenience.cxx TestArrayAPIDense.cxx diff --git a/Common/Core/Testing/Cxx/TestAbstractArraySize.cxx b/Common/Core/Testing/Cxx/TestAbstractArraySize.cxx new file mode 100644 index 000000000..4adb23836 --- /dev/null +++ b/Common/Core/Testing/Cxx/TestAbstractArraySize.cxx @@ -0,0 +1,61 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: TestAbstractArraySize.cxx + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + +#include +#include +#include + +#include +#include +#include + +int TestAbstractArraySize(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) +{ + int status = 0; + vtkNew stringArray; + stringArray->SetNumberOfComponents(2); + stringArray->SetNumberOfTuples(1); + std::cout << "Size is now " << stringArray->GetSize() << "\n"; + if (stringArray->GetMaxId() < 1) + { + std::cerr << "Allocation failed: number of tuples requested not provided.\n"; + status = 1; + } + // Test for regression + stringArray->SetValue(0, "This value is OK."); + stringArray->SetValue(1, "This used to crash, even though GetMaxId reported a proper size."); + + // Test for desired behavior + stringArray->SetNumberOfValues(3); + std::cout << "Size is now " << stringArray->GetSize() << "\n"; + if (stringArray->GetSize() < 4) + { + std::cerr + << "Allocation failed: SetNumberOfValues should always allocate to a tuple boundary.\n"; + status = 1; + } + // Same as above, but test a vtkDataArray subclass. + vtkNew doubleArray; + doubleArray->SetNumberOfComponents(3); + doubleArray->SetNumberOfValues(7); + if (doubleArray->GetSize() != 9) + { + std::cerr + << "Allocation failed: SetNumberOfValues should always allocate to a tuple boundary.\n"; + status = 1; + } + + return status; +} diff --git a/Common/Core/vtkAbstractArray.cxx b/Common/Core/vtkAbstractArray.cxx index 0ade36cff..358b9f1dc 100644 --- a/Common/Core/vtkAbstractArray.cxx +++ b/Common/Core/vtkAbstractArray.cxx @@ -190,9 +190,11 @@ int vtkAbstractArray::CopyComponentNames(vtkAbstractArray* da) //---------------------------------------------------------------------------- bool vtkAbstractArray::SetNumberOfValues(vtkIdType numValues) { - vtkIdType numTuples = this->NumberOfComponents == 1 - ? numValues - : (numValues + this->NumberOfComponents - 1) / this->NumberOfComponents; + vtkIdType numTuples = numValues / this->NumberOfComponents; + if (numValues % this->NumberOfComponents) + { + ++numTuples; + } if (!this->Resize(numTuples)) { return false; diff --git a/Common/Core/vtkSetGet.h b/Common/Core/vtkSetGet.h index 39668094a..de97f8b07 100644 --- a/Common/Core/vtkSetGet.h +++ b/Common/Core/vtkSetGet.h @@ -142,6 +142,34 @@ return this->name; \ } +// +// Set 'enum class' type. Creates member Set"name"() (e.g., SetKind()); +// vtkSetMacro can't be used because 'enum class' won't trivially convert to integer for logging. +// +#define vtkSetEnumMacro(name, enumType) \ + virtual void Set##name(enumType _arg) \ + { \ + vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " #name " to " \ + << static_cast::type>(_arg)); \ + if (this->name != _arg) \ + { \ + this->name = _arg; \ + this->Modified(); \ + } \ + } + +// +// Get 'enum class' type. Creates member Get"name"() (e.g., GetKind()); +// vtkSetMacro can't be used because 'enum class' won't trivially convert to integer for logging. +// +#define vtkGetEnumMacro(name, enumType) \ + virtual enumType Get##name() const \ + { \ + vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " of " \ + << static_cast::type>(this->name)); \ + return this->name; \ + } + // // Set character string. Creates member Set"name"() // (e.g., SetFilename(char *)); diff --git a/Common/Core/vtkStringArray.cxx b/Common/Core/vtkStringArray.cxx index 073a4a273..052d48037 100644 --- a/Common/Core/vtkStringArray.cxx +++ b/Common/Core/vtkStringArray.cxx @@ -399,7 +399,7 @@ vtkStdString* vtkStringArray::ResizeAndExtend(vtkIdType sz) vtkTypeBool vtkStringArray::Resize(vtkIdType sz) { vtkStdString* newArray; - vtkIdType newSize = sz; + vtkIdType newSize = sz * this->NumberOfComponents; if (newSize == this->Size) { diff --git a/Documentation/release/9.0.md b/Documentation/release/9.0.md new file mode 100644 index 000000000..6207ebcf4 --- /dev/null +++ b/Documentation/release/9.0.md @@ -0,0 +1,71 @@ +# 9.0.0 + +See [Discourse](https://discourse.vtk.org/t/vtk-9-0-0/3205) for release notes. + +# 9.0.2 + +VTK 9.0.2 collects fixes to 9.0.1 which have been made since its release. Of +particular interest are the fixes to macOS rendering, support for the macOS +arm64 platform, and updates for API changes in external libraries. + +# New classes + + - Added a `vtkImageProbeFilter` which works like `vtkProbeFilter`, but for + `vtkImageData` + +# New support + + - `enum class` setters and getters are now supported via + `vtk{Get,Set}EnumMacro` + +# Fixes + + - The `QVTKRenderWidget.h` is now installed. + - `vtk3DLinearGridPlaneCutter` guards against `nullptr` points and cells + - The composite date mapper now iterates over data blocks properly + - `vtkStringArray::Resize` takes tuple elements into account + - `vtkArrowSource` now supports scalong and rotation around the origin or the + arrow's center point + - The `VTK::DomainsChemistryOpenGL2`, `VTK::RenderingContextOpenGL2`, and + `VTK::RenderingOpenGL2` modules are added to the `Rendering` group to avoid + missing implementations of rendering components + - `vtkCutter` enables point merging when requested through a + `vtkPointLocator` which merges points + - `vtkAxesActor` bounds calculations improved to avoid assumptions about + range values + - `vtkWindowLevelLookupTable` out-of-range colors are now initialized + properly + - `vtkImageReslice::RequestInformation` is refactored handle common image + information passing + - `vtkImageReslice` creates a new interpolator in `::GetInterpolator`; this + new interpolator now uses the same interpolation mode as `vtkImageReslice` + itself + +## macOS + + - macOS wheels are now built and uploaded by VTK's CI + - Fixes for macOS OpenGL state tracking (related to `GL_SCISSOR`) + - Multisampling on macOS with Intel graphics turned off for volume rendering + - OpenGL state tracking on macOS with layers is improved (rather than using + the wrong context between layers) + - OSPRay is disabled when running under macOS Rosetta + +## Third Party + + - HDF5 has been updated to address errors on newer Xcode compilers + - HDF5 macOS universal2 compilation fixes + - `VTK::mpi` now disables C++ bindings for SGI MPT as well + - Usage of `numpy.character` is removed (deprecated in NumPy 1.19) + - Avoidance of APIs deprecated in Python 3.9 + - Compilation with newer libfreetype resolved (`FT_CALLBACK_DEF` usage + removed) + +# 9.0.3 + +A minor patchset on top of 9.0.2 to fix problems with the new release process' +configuration when building the wheels. + +## Wheels + + - Disable `VTK_DEBUG_LEAKS` in wheel builds + - Remove long-deprecated API usage in the Python bindings diff --git a/Documentation/release/dev/node-numbering-change-for-VTK_LAGRANGE_HEXAHEDRON.md b/Documentation/release/dev/node-numbering-change-for-VTK_LAGRANGE_HEXAHEDRON.md deleted file mode 100644 index 55d75467b..000000000 --- a/Documentation/release/dev/node-numbering-change-for-VTK_LAGRANGE_HEXAHEDRON.md +++ /dev/null @@ -1,28 +0,0 @@ -# node-numbering-change-for-VTK_LAGRANGE_HEXAHEDRON - -The node numbering for VTK_LAGRANGE_HEXAHEDRON has been corrected, -to match the numbering of VTK_QUADRATIC_HEXAHEDRON when the Lagrange -cell is quadratic. -The change consists in inverting the node numbering on the edge (x=0, y=1) -with the edge (x=1, y=1), has shown below for a quadratic cell. - - - quadratic VTK_QUADRATIC_HEXAHEDRON -VTK_LAGRANGE_HEXAHEDRON VTK_LAGRANGE_HEXAHEDRON - before VTK 9.0 after VTK 9.0 - - +_____+_____+ +_____+_____+ - |\ :\ |\ :\ - | + : + | + : + - | \ 19 + \ | \ 18 + \ - 18 + +-----+-----+ 19 + +-----+-----+ - | | : | | | : | - |__ | _+____: | |__ | _+____: | - \ + \ + \ + \ + - + | + | + | + | - \ | \| \ | \| - +_____+_____+ +_____+_____+ - -In order to maintain the compatibility, the readers can convert internally -existing files to the new numbering. To this end, The XML file version has been -bumped from 2.1 to 2.2 and the legacy file version has been bumped from 5.0 to 5.1. diff --git a/Documentation/release/dev/pegtl.md b/Documentation/release/dev/pegtl.md deleted file mode 100644 index 977d4c8a8..000000000 --- a/Documentation/release/dev/pegtl.md +++ /dev/null @@ -1,3 +0,0 @@ -# pegtl - -VTK can now be built against an external PEGTL library. diff --git a/Domains/ChemistryOpenGL2/vtk.module b/Domains/ChemistryOpenGL2/vtk.module index 7a1f08cf7..8c1973259 100644 --- a/Domains/ChemistryOpenGL2/vtk.module +++ b/Domains/ChemistryOpenGL2/vtk.module @@ -4,6 +4,8 @@ LIBRARY_NAME vtkDomainsChemistryOpenGL2 DESCRIPTION OpenGL support for chemistry data +GROUPS + Rendering IMPLEMENTS VTK::DomainsChemistry DEPENDS diff --git a/Examples/GUI/Cocoa/CustomLayer.mm b/Examples/GUI/Cocoa/CustomLayer.mm index 6bbaa50b1..9238023e5 100644 --- a/Examples/GUI/Cocoa/CustomLayer.mm +++ b/Examples/GUI/Cocoa/CustomLayer.mm @@ -27,7 +27,9 @@ vtkCocoaRenderWindow* renderWindow = [customView renderWindow]; if (renderWindow && renderWindow->GetMapped()) { - renderWindow->InitializeFromCurrentContext(); + bool contextInitialised = renderWindow->Superclass::InitializeFromCurrentContext(); + assert(contextInitialised); + (void)contextInitialised; renderWindow->Render(); } diff --git a/Examples/GUI/Cocoa/MyWindowController.mm b/Examples/GUI/Cocoa/MyWindowController.mm index 4c96ce5c5..40ee96bd7 100644 --- a/Examples/GUI/Cocoa/MyWindowController.mm +++ b/Examples/GUI/Cocoa/MyWindowController.mm @@ -51,7 +51,10 @@ BasicVTKView* thisView = [self leftView]; // Explicitly enable HiDPI/Retina (this is the default anyway). +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [thisView setWantsBestResolutionOpenGLSurface:YES]; +#pragma clang diagnostic pop [thisView initializeVTKSupport]; @@ -104,7 +107,10 @@ // Explicitly disable HiDPI/Retina as a demonstration of the difference. // One might want to disable it to reduce memory usage / increase performance. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [thisView setWantsBestResolutionOpenGLSurface:NO]; +#pragma clang diagnostic pop [thisView initializeVTKSupport]; @@ -155,7 +161,10 @@ // Explicitly enable HiDPI/Retina (this is required when using CAOpenGLLayer, otherwise the view // will be 1/4 size on Retina). +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [thisView setWantsBestResolutionOpenGLSurface:YES]; +#pragma clang diagnostic pop [thisView initializeVTKSupport]; [thisView initializeLayerSupport]; diff --git a/Filters/Core/vtk3DLinearGridPlaneCutter.cxx b/Filters/Core/vtk3DLinearGridPlaneCutter.cxx index a4f7f0d1f..ae3190fee 100644 --- a/Filters/Core/vtk3DLinearGridPlaneCutter.cxx +++ b/Filters/Core/vtk3DLinearGridPlaneCutter.cxx @@ -852,14 +852,20 @@ int vtk3DLinearGridPlaneCutter::ProcessPiece( vtkUnstructuredGrid* input, vtkPlane* plane, vtkPolyData* output) { // Make sure there is input data to process + if (!input || !plane || !output) + { + vtkLog(INFO, "Null input, plane, or output"); + return 1; + } + vtkPoints* inPts = input->GetPoints(); - vtkIdType numPts = inPts->GetNumberOfPoints(); + vtkIdType numPts = inPts ? inPts->GetNumberOfPoints() : 0; vtkCellArray* cells = input->GetCells(); - vtkIdType numCells = cells->GetNumberOfCells(); + vtkIdType numCells = cells ? cells->GetNumberOfCells() : 0; if (numPts <= 0 || numCells <= 0) { vtkLog(INFO, "Empty input"); - return 0; + return 1; } // Check the input point type. Only real types are supported. diff --git a/Filters/Core/vtkCutter.cxx b/Filters/Core/vtkCutter.cxx index 54abef95e..08396549c 100644 --- a/Filters/Core/vtkCutter.cxx +++ b/Filters/Core/vtkCutter.cxx @@ -405,6 +405,9 @@ int vtkCutter::RequestData( newPlane->Push(-d + this->GetValue(0)); linear3DCutter->SetPlane(newPlane); + bool mergePoints = + this->GetLocator() && !this->GetLocator()->IsA("vtkNonMergingPointLocator"); + linear3DCutter->SetMergePoints(mergePoints); linear3DCutter->SetOutputPointsPrecision(this->GetOutputPointsPrecision()); linear3DCutter->SetInputArrayToProcess(0, this->GetInputArrayInformation(0)); vtkNew progressForwarder; diff --git a/Filters/Sources/Testing/Cxx/CMakeLists.txt b/Filters/Sources/Testing/Cxx/CMakeLists.txt index f0edb1df1..263b4e642 100644 --- a/Filters/Sources/Testing/Cxx/CMakeLists.txt +++ b/Filters/Sources/Testing/Cxx/CMakeLists.txt @@ -1,5 +1,6 @@ vtk_add_test_cxx(vtkFiltersSourcesCxxTests tests TestArcSource.cxx,NO_VALID + TestArrowSource.cxx TestCapsuleSource.cxx,NO_VALID TestCellTypeSource.cxx,NO_VALID TestConeSource.cxx,NO_VALID diff --git a/Filters/Sources/Testing/Cxx/TestArrowSource.cxx b/Filters/Sources/Testing/Cxx/TestArrowSource.cxx new file mode 100644 index 000000000..ba32ced15 --- /dev/null +++ b/Filters/Sources/Testing/Cxx/TestArrowSource.cxx @@ -0,0 +1,149 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: TestArrowSource.cxx + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int TestArrowSource(int argc, char* argv[]) +{ + vtkSmartPointer arrow = vtkSmartPointer::New(); + vtkSmartPointer arrowCentral = vtkSmartPointer::New(); + vtkSmartPointer arrowInvertCentral = vtkSmartPointer::New(); + + double shaftRadius = arrow->GetShaftRadius(); + arrow->SetShaftRadius(shaftRadius * 2.0); + arrowCentral->SetShaftRadius(shaftRadius * 2.0); + arrowInvertCentral->SetShaftRadius(shaftRadius * 2.0); + + double shaftRes = arrow->GetShaftResolution(); + arrow->SetShaftResolution(shaftRes * 15.0); + arrowCentral->SetShaftResolution(shaftRes * 15.0); + arrowInvertCentral->SetShaftResolution(shaftRes * 15.0); + + double tipRes = arrow->GetTipResolution(); + arrow->SetTipResolution(tipRes * 10.0); + arrowCentral->SetTipResolution(tipRes * 10.0); + arrowInvertCentral->SetTipResolution(tipRes * 10.0); + + // Centralize just these arrows + arrowCentral->SetArrowOriginToCenter(); + arrowInvertCentral->SetArrowOriginToCenter(); + + // Invert only this arrow + arrowInvertCentral->InvertOn(); + + arrow->Update(); + arrowCentral->Update(); + arrowInvertCentral->Update(); + + vtkSmartPointer polydata = arrow->GetOutput(); + vtkSmartPointer polydataCentral = arrowCentral->GetOutput(); + vtkSmartPointer polydataInvertCentral = arrowInvertCentral->GetOutput(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + vtkSmartPointer mapperCentral = vtkSmartPointer::New(); + vtkSmartPointer mapperInvertCentral = + vtkSmartPointer::New(); + + mapper->SetInputData(polydata); + mapper->ScalarVisibilityOff(); + + mapperCentral->SetInputData(polydataCentral); + mapperCentral->ScalarVisibilityOff(); + + mapperInvertCentral->SetInputData(polydataInvertCentral); + mapperInvertCentral->ScalarVisibilityOff(); + + // Normal Arrow + vtkActor* actor = vtkActor::New(); + actor->SetMapper(mapper); + actor->SetPosition(0.0, 0.325, 0.0); + + vtkProperty* propertyToSet = actor->GetProperty(); + propertyToSet->SetDiffuseColor(0.501, 1.0, 0.0); + propertyToSet->SetSpecular(0.15); + propertyToSet->SetSpecularPower(5.0); + + // Centralized Arrow + vtkActor* actorCentral = vtkActor::New(); + actorCentral->SetMapper(mapperCentral); + actorCentral->SetPosition(0.0, 0.0, 0.0); + + vtkProperty* propertyToSetCentral = actorCentral->GetProperty(); + propertyToSetCentral->SetDiffuseColor(1.0, 0.647, 0.0); + propertyToSetCentral->SetSpecular(0.15); + propertyToSetCentral->SetSpecularPower(5.0); + + // Inverted - Centralized Arrow + vtkActor* actorInvertCentral = vtkActor::New(); + actorInvertCentral->SetMapper(mapperInvertCentral); + actorInvertCentral->SetPosition(0.0, -0.325, 0.0); + + vtkProperty* propertyToSetInvertCentral = actorInvertCentral->GetProperty(); + propertyToSetInvertCentral->SetDiffuseColor(0.2, 0.8, 1.0); + propertyToSetInvertCentral->SetSpecular(0.25); + propertyToSetInvertCentral->SetSpecularPower(5.0); + + // Setup renderer. + vtkRenderer* ren = vtkRenderer::New(); + vtkRenderWindow* win = vtkRenderWindow::New(); + win->SetMultiSamples(0); // make sure regression images are the same on all platforms + win->AddRenderer(ren); + ren->Delete(); + vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New(); + iren->SetRenderWindow(win); + win->Delete(); + + // Add all arrow actors for display. + ren->AddActor(actor); + ren->AddActor(actorCentral); + ren->AddActor(actorInvertCentral); + + // cleanup. + actor->Delete(); + actorCentral->Delete(); + actorInvertCentral->Delete(); + + ren->SetBackground(0.0, 0.0, 0.0); + win->SetSize(450, 450); + + vtkCamera* cam = ren->GetActiveCamera(); + cam->SetPosition(-2.3332, 1.0, 2.25); + + int retVal = vtkRegressionTestImage(win); + if (retVal == vtkRegressionTester::DO_INTERACTOR) + { + iren->Start(); + } + iren->Delete(); + + return !retVal; +} diff --git a/Filters/Sources/Testing/Data/Baseline/TestArrowSource.png.sha512 b/Filters/Sources/Testing/Data/Baseline/TestArrowSource.png.sha512 new file mode 100644 index 000000000..345aedf87 --- /dev/null +++ b/Filters/Sources/Testing/Data/Baseline/TestArrowSource.png.sha512 @@ -0,0 +1 @@ +c56092b0815e27a8fd60770064c8ac696063d20e7580d4b3ada043547f290c9883274f299dcf38fc9be6bab01019c2b2c486fd01638543d8837a098956ee39b5 diff --git a/Filters/Sources/vtkArrowSource.cxx b/Filters/Sources/vtkArrowSource.cxx index 53ba01ce1..6a85e4713 100644 --- a/Filters/Sources/vtkArrowSource.cxx +++ b/Filters/Sources/vtkArrowSource.cxx @@ -27,6 +27,7 @@ vtkStandardNewMacro(vtkArrowSource); +//------------------------------------------------------------------------------ vtkArrowSource::vtkArrowSource() { this->TipResolution = 6; @@ -35,10 +36,12 @@ vtkArrowSource::vtkArrowSource() this->ShaftResolution = 6; this->ShaftRadius = 0.03; this->Invert = false; + this->ArrowOrigin = ArrowOrigins::Default; this->SetNumberOfInputPorts(0); } +//------------------------------------------------------------------------------ int vtkArrowSource::RequestInformation( vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector) { @@ -46,6 +49,7 @@ int vtkArrowSource::RequestInformation( return Superclass::RequestInformation(request, inputVector, outputVector); } +//------------------------------------------------------------------------------ int vtkArrowSource::RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector) { @@ -97,17 +101,41 @@ int vtkArrowSource::RequestData(vtkInformation* vtkNotUsed(request), tf2->SetTransform(trans2); tf2->SetInputConnection(append->GetOutputPort()); + // used only when this->ArrowOrigin is Center (we aim to orient and scale from the centre). + vtkTransform* trans3 = vtkTransform::New(); + vtkTransformFilter* tf3 = vtkTransformFilter::New(); + trans3->Translate(-0.5, 0.0, 0.0); + tf3->SetTransform(trans3); + if (piece == 0 && numPieces > 0) { if (this->Invert) { - tf2->Update(); - output->ShallowCopy(tf2->GetOutput()); + if (this->ArrowOrigin == ArrowOrigins::Center) + { + tf3->SetInputConnection(tf2->GetOutputPort()); + tf3->Update(); + output->ShallowCopy(tf3->GetOutput()); + } + else + { + tf2->Update(); + output->ShallowCopy(tf2->GetOutput()); + } } else { - append->Update(); - output->ShallowCopy(append->GetOutput()); + if (this->ArrowOrigin == ArrowOrigins::Center) + { + tf3->SetInputConnection(append->GetOutputPort()); + tf3->Update(); + output->ShallowCopy(tf3->GetOutput()); + } + else + { + append->Update(); + output->ShallowCopy(append->GetOutput()); + } } } @@ -120,10 +148,26 @@ int vtkArrowSource::RequestData(vtkInformation* vtkNotUsed(request), append->Delete(); tf2->Delete(); trans2->Delete(); + tf3->Delete(); + trans3->Delete(); return 1; } +//------------------------------------------------------------------------------ +std::string vtkArrowSource::GetArrowOriginAsString() const +{ + switch (this->ArrowOrigin) + { + case ArrowOrigins::Default: + return "Default"; + case ArrowOrigins::Center: + return "Center"; + } + return "Invalid"; +} + +//------------------------------------------------------------------------------ void vtkArrowSource::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); @@ -136,4 +180,5 @@ void vtkArrowSource::PrintSelf(ostream& os, vtkIndent indent) os << indent << "ShaftRadius: " << this->ShaftRadius << "\n"; os << indent << "Invert: " << this->Invert << "\n"; + os << indent << "Arrow Origin: " << this->GetArrowOriginAsString() << endl; } diff --git a/Filters/Sources/vtkArrowSource.h b/Filters/Sources/vtkArrowSource.h index 2d7972b9c..fd30f558f 100644 --- a/Filters/Sources/vtkArrowSource.h +++ b/Filters/Sources/vtkArrowSource.h @@ -90,6 +90,25 @@ public: vtkGetMacro(Invert, bool); //@} + enum class ArrowOrigins + { + Default = 0, + Center = 1 + }; + + //@{ + /** + * Sets and Gets the location used for orienting and scaling the arrow. + * Default is set to Default. + */ + vtkSetEnumMacro(ArrowOrigin, ArrowOrigins); + vtkGetEnumMacro(ArrowOrigin, ArrowOrigins); + //@} + + void SetArrowOriginToDefault() { this->SetArrowOrigin(ArrowOrigins::Default); } + void SetArrowOriginToCenter() { this->SetArrowOrigin(ArrowOrigins::Center); } + std::string GetArrowOriginAsString() const; + protected: vtkArrowSource(); ~vtkArrowSource() override {} @@ -104,6 +123,7 @@ protected: int ShaftResolution; double ShaftRadius; bool Invert; + ArrowOrigins ArrowOrigin; private: vtkArrowSource(const vtkArrowSource&) = delete; diff --git a/Filters/Verdict/vtkMatrixMathFilter.cxx b/Filters/Verdict/vtkMatrixMathFilter.cxx index d3e96510b..fa808bbff 100644 --- a/Filters/Verdict/vtkMatrixMathFilter.cxx +++ b/Filters/Verdict/vtkMatrixMathFilter.cxx @@ -41,7 +41,7 @@ void vtkMatrixMathFilter::PrintSelf(ostream& os, vtkIndent indent) static const char* OperationNames[] = { "None", "Determinant", - "Eigenvalue" + "Eigenvalue", "Eigenvector", "Inverse", }; diff --git a/GUISupport/Qt/CMakeLists.txt b/GUISupport/Qt/CMakeLists.txt index bfa63a94f..e99e27790 100644 --- a/GUISupport/Qt/CMakeLists.txt +++ b/GUISupport/Qt/CMakeLists.txt @@ -25,6 +25,7 @@ if (VTK_USE_X AND VTK_USE_TDX) endif () set(headers + QVTKRenderWidget.h QVTKWin32Header.h) set(private_headers diff --git a/Imaging/Core/CMakeLists.txt b/Imaging/Core/CMakeLists.txt index e182442b9..d4b15923a 100644 --- a/Imaging/Core/CMakeLists.txt +++ b/Imaging/Core/CMakeLists.txt @@ -1,4 +1,5 @@ set(classes + vtkImageProbeFilter vtkAbstractImageInterpolator vtkExtractVOI vtkImageAppendComponents diff --git a/Imaging/Core/Testing/Cxx/CMakeLists.txt b/Imaging/Core/Testing/Cxx/CMakeLists.txt index 12c4b8a70..80040dfa7 100644 --- a/Imaging/Core/Testing/Cxx/CMakeLists.txt +++ b/Imaging/Core/Testing/Cxx/CMakeLists.txt @@ -15,6 +15,7 @@ vtk_add_test_cxx(vtkImagingCoreCxxTests tests ImageWeightedSum.cxx,NO_VALID ImportExport.cxx,NO_VALID TestBSplineWarp.cxx + TestImageProbeFilter.cxx TestImageStencilDataMethods.cxx,NO_VALID TestImageStencilIterator.cxx,NO_VALID TestStencilWithLasso.cxx diff --git a/Imaging/Core/Testing/Cxx/TestImageProbeFilter.cxx b/Imaging/Core/Testing/Cxx/TestImageProbeFilter.cxx new file mode 100644 index 000000000..9f2506cdd --- /dev/null +++ b/Imaging/Core/Testing/Cxx/TestImageProbeFilter.cxx @@ -0,0 +1,251 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: TestImageProbeFilter.cxx + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + +#include "vtkImageProbeFilter.h" + +#include "vtkNew.h" + +#include "vtkActor.h" +#include "vtkCamera.h" +#include "vtkDataSetMapper.h" +#include "vtkImageCast.h" +#include "vtkImageData.h" +#include "vtkImageInterpolator.h" +#include "vtkImageMapToColors.h" +#include "vtkImageProperty.h" +#include "vtkImageReader2.h" +#include "vtkInteractorStyleImage.h" +#include "vtkLookupTable.h" +#include "vtkMath.h" +#include "vtkPlaneSource.h" +#include "vtkPoints.h" +#include "vtkRenderWindow.h" +#include "vtkRenderWindowInteractor.h" +#include "vtkRenderer.h" +#include "vtkSphereSource.h" +#include "vtkTransform.h" + +#include + +#include "vtkRegressionTestImage.h" +#include "vtkTestUtilities.h" + +int TestImageProbeFilter(int argc, char* argv[]) +{ + // render window and interactor + vtkNew renWin; + vtkNew iren; + iren->SetRenderWindow(renWin); + renWin->SetSize(512, 512); + + // image file information (because the file is raw) + int extent[6] = { 0, 63, 0, 63, 1, 93 }; + double origin[3] = { 0.0, 0.0, 0.0 }; + double spacing[3] = { 3.2, 3.2, 1.5 }; + char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/headsq/quarter"); + std::string filename = fname; + delete[] fname; + + // read a CT image + vtkNew reader; + reader->SetDataByteOrderToLittleEndian(); + reader->SetDataExtent(extent); + reader->SetDataOrigin(origin); + reader->SetDataSpacing(spacing); + reader->SetFilePrefix(filename.c_str()); + + // grayscale lookup table + vtkNew table; + table->SetRampToLinear(); + table->SetRange(0.0, 4095.0); + table->SetValueRange(0.0, 1.0); + table->SetSaturationRange(0.0, 0.0); + table->Build(); + + // create RGBA data for rendering + vtkNew colors; + colors->SetOutputFormatToRGBA(); + colors->SetInputConnection(reader->GetOutputPort()); + colors->SetLookupTable(table); + + { // probe RGBA data onto a plane, default probing + + // a plane for probing with + vtkNew plane; + plane->SetOrigin(0.0, 0.0, 69.75); + plane->SetPoint1(201.6, 0.0, 69.75); + plane->SetPoint2(0.0, 201.6, 69.75); + plane->SetXResolution(63); + plane->SetYResolution(63); + + // the probe filter + vtkNew probe; + probe->SetSourceConnection(colors->GetOutputPort()); + probe->SetInputConnection(plane->GetOutputPort()); + + vtkNew mapper; + mapper->SetInputConnection(probe->GetOutputPort()); + + vtkNew actor; + actor->SetMapper(mapper); + + vtkNew ren; + ren->AddViewProp(actor); + ren->ResetCamera(); + ren->GetActiveCamera()->ParallelProjectionOn(); + ren->GetActiveCamera()->SetParallelScale(102.4); + ren->SetViewport(0.0, 0.5, 0.5, 1.0); + renWin->AddRenderer(ren); + } + + { // probe RGBA data onto a plane, via cubic interpolation + + // a plane for probing with + vtkNew plane; + plane->SetOrigin(0.0, 0.0, 69.75); + plane->SetPoint1(201.6, 0.0, 69.75); + plane->SetPoint2(0.0, 201.6, 69.75); + plane->SetXResolution(255); + plane->SetYResolution(255); + + // an interpolator (cubic interpolation) + vtkNew interpolator; + interpolator->SetInterpolationModeToCubic(); + + // the probe filter + vtkNew probe; + probe->SetInterpolator(interpolator); + probe->SetSourceConnection(colors->GetOutputPort()); + probe->SetInputConnection(plane->GetOutputPort()); + + vtkNew mapper; + mapper->SetInputConnection(probe->GetOutputPort()); + + vtkNew actor; + actor->SetMapper(mapper); + + vtkNew ren; + ren->AddViewProp(actor); + ren->ResetCamera(); + ren->GetActiveCamera()->ParallelProjectionOn(); + ren->GetActiveCamera()->SetParallelScale(102.4); + ren->SetViewport(0.5, 0.5, 1.0, 1.0); + renWin->AddRenderer(ren); + } + + { // probe int data onto oblique plane, via cubic interpolation + + // plane information + double center[3] = { 100.8, 100.8, 69.75 }; + double p0[3] = { 0.0, 0.0, 69.75 }; + double p1[3] = { 201.6, 0.0, 69.75 }; + double p2[3] = { 0.0, 201.6, 69.75 }; + + // a transform for going oblique + vtkNew transform; + transform->PostMultiply(); + vtkMath::MultiplyScalar(center, -1.0); + transform->Translate(center); + vtkMath::MultiplyScalar(center, -1.0); + transform->RotateWXYZ(-20.0, 0.99388, 0.0, 0.11043); + transform->Translate(center); + transform->TransformPoint(p0, p0); + transform->TransformPoint(p1, p1); + transform->TransformPoint(p2, p2); + + // a plane for probing with + vtkNew plane; + plane->SetOrigin(p0); + plane->SetPoint1(p1); + plane->SetPoint2(p2); + plane->SetXResolution(255); + plane->SetYResolution(255); + + // an interpolator (cubic interpolation) + vtkNew interpolator; + interpolator->SetInterpolationModeToCubic(); + + // the probe filter + vtkNew probe; + probe->SetInterpolator(interpolator); + probe->SetSourceConnection(reader->GetOutputPort()); + probe->SetInputConnection(plane->GetOutputPort()); + + vtkNew mapper; + mapper->SetInputConnection(probe->GetOutputPort()); + mapper->SetLookupTable(table); + mapper->UseLookupTableScalarRangeOn(); + + vtkNew actor; + actor->SetMapper(mapper); + + vtkNew ren; + ren->AddViewProp(actor); + ren->ResetCamera(); + ren->GetActiveCamera()->ParallelProjectionOn(); + ren->GetActiveCamera()->SetParallelScale(102.4); + ren->SetViewport(0.0, 0.0, 0.5, 0.5); + renWin->AddRenderer(ren); + } + + { // probe float data onto sphere, via linear interpolation + + // a sphere for probing with + vtkNew surface; + surface->SetCenter(100.8, 100.8, 69.75); + surface->SetRadius(60.0); + surface->SetPhiResolution(200); + surface->SetThetaResolution(200); + + // use floating-point here for coverage + vtkNew cast; + cast->SetInputConnection(reader->GetOutputPort()); + cast->SetOutputScalarTypeToFloat(); + + // an interpolator (linear interpolation) + vtkNew interpolator; + + // the probe filter + vtkNew probe; + probe->SetInterpolator(interpolator); + probe->SetSourceConnection(cast->GetOutputPort()); + probe->SetInputConnection(surface->GetOutputPort()); + + vtkNew mapper; + mapper->SetInputConnection(probe->GetOutputPort()); + mapper->SetLookupTable(table); + mapper->UseLookupTableScalarRangeOn(); + + vtkNew actor; + actor->SetMapper(mapper); + + vtkNew ren; + ren->AddViewProp(actor); + ren->ResetCamera(); + ren->GetActiveCamera()->ParallelProjectionOn(); + ren->GetActiveCamera()->SetParallelScale(102.4); + ren->SetViewport(0.5, 0.0, 1.0, 0.5); + renWin->AddRenderer(ren); + } + + renWin->Render(); + + int retVal = vtkRegressionTestImage(renWin); + if (retVal == vtkRegressionTester::DO_INTERACTOR) + { + iren->Start(); + } + return !retVal; +} diff --git a/Imaging/Core/Testing/Data/Baseline/TestImageProbeFilter.png.sha512 b/Imaging/Core/Testing/Data/Baseline/TestImageProbeFilter.png.sha512 new file mode 100644 index 000000000..ea95e58f8 --- /dev/null +++ b/Imaging/Core/Testing/Data/Baseline/TestImageProbeFilter.png.sha512 @@ -0,0 +1 @@ +cb67b346066f07d9889a844b9caf34b8b79068dfea439cb52b8cadc8bb7a82e8ed6e49ee25ee38a04d3dde89ceb201b99931de7fe9b274ded8117916c90dd3ed diff --git a/Imaging/Core/vtkImageFlip.cxx b/Imaging/Core/vtkImageFlip.cxx index 0bce6aaa3..fbc5fc166 100644 --- a/Imaging/Core/vtkImageFlip.cxx +++ b/Imaging/Core/vtkImageFlip.cxx @@ -98,17 +98,7 @@ int vtkImageFlip::RequestInformation(vtkInformation* vtkNotUsed(request), outInfo->Set(vtkDataObject::SPACING(), spacing, 3); outInfo->Set(vtkDataObject::ORIGIN(), origin, 3); - vtkInformation* inScalarInfo = vtkDataObject::GetActiveFieldInformation( - inInfo, vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::SCALARS); - if (!inScalarInfo) - { - vtkErrorMacro("Missing scalar field on input information!"); - return 0; - } - vtkDataObject::SetPointDataActiveScalarInfo(outInfo, - inScalarInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE()), - inScalarInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS())); - return 1; + return this->RequestInformationBase(inputVector, outputVector); } //---------------------------------------------------------------------------- diff --git a/Imaging/Core/vtkImageProbeFilter.cxx b/Imaging/Core/vtkImageProbeFilter.cxx new file mode 100644 index 000000000..93a808b7d --- /dev/null +++ b/Imaging/Core/vtkImageProbeFilter.cxx @@ -0,0 +1,400 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: vtkImageProbeFilter.cxx + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +#include "vtkImageProbeFilter.h" + +#include "vtkImageData.h" +#include "vtkImageInterpolator.h" +#include "vtkInformation.h" +#include "vtkInformationVector.h" +#include "vtkMath.h" +#include "vtkObjectFactory.h" +#include "vtkPointData.h" +#include "vtkSMPThreadLocal.h" +#include "vtkSMPTools.h" +#include "vtkSmartPointer.h" +#include "vtkStreamingDemandDrivenPipeline.h" +#include "vtkUnsignedCharArray.h" + +#include +#include + +vtkStandardNewMacro(vtkImageProbeFilter); + +vtkCxxSetObjectMacro(vtkImageProbeFilter, Interpolator, vtkAbstractImageInterpolator); + +//------------------------------------------------------------------------------ +vtkImageProbeFilter::vtkImageProbeFilter() +{ + // Default is no interpolation + this->Interpolator = nullptr; + + // Inputs are "Input" and "Source" + this->SetNumberOfInputPorts(2); + + // The mask for Input points that intersect the Source image. + this->MaskScalars = nullptr; + + // Process active point scalars on "Source" input + this->SetInputArrayToProcess( + 0, 1, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::SCALARS); +} + +//------------------------------------------------------------------------------ +vtkImageProbeFilter::~vtkImageProbeFilter() +{ + if (this->Interpolator) + { + this->Interpolator->Delete(); + } +} + +//------------------------------------------------------------------------------ +int vtkImageProbeFilter::FillInputPortInformation(int port, vtkInformation* info) +{ + if (port == 1) + { + info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkImageData"); + } + else + { + info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataSet"); + } + return 1; +} + +//------------------------------------------------------------------------------ +void vtkImageProbeFilter::SetSourceConnection(vtkAlgorithmOutput* algOutput) +{ + this->SetInputConnection(1, algOutput); +} + +//------------------------------------------------------------------------------ +void vtkImageProbeFilter::SetSourceData(vtkDataObject* input) +{ + this->SetInputData(1, input); +} + +//------------------------------------------------------------------------------ +vtkDataObject* vtkImageProbeFilter::GetSource() +{ + if (this->GetNumberOfInputConnections(1) < 1) + { + return nullptr; + } + + return this->GetExecutive()->GetInputData(1, 0); +} + +//------------------------------------------------------------------------------ +int vtkImageProbeFilter::RequestData(vtkInformation* vtkNotUsed(request), + vtkInformationVector** inputVector, vtkInformationVector* outputVector) +{ + // get the info objects + vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation* sourceInfo = inputVector[1]->GetInformationObject(0); + vtkInformation* outInfo = outputVector->GetInformationObject(0); + + // get the input and output + vtkDataSet* input = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT())); + vtkImageData* source = vtkImageData::SafeDownCast(sourceInfo->Get(vtkDataObject::DATA_OBJECT())); + vtkDataSet* output = vtkDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())); + + // copy the geometry of the Input to the Output + output->CopyStructure(input); + + // probe the Source to generate the Output attributes + if (source) + { + this->Probe(input, source, output); + } + + return 1; +} + +//------------------------------------------------------------------------------ +void vtkImageProbeFilter::InitializeForProbing( + vtkDataSet* input, vtkImageData* source, vtkDataSet* output) +{ + // Get information about the input + vtkIdType numPts = input->GetNumberOfPoints(); + vtkDataArray* inScalars = source->GetPointData()->GetScalars(); + int scalarType = inScalars->GetDataType(); + int numComponents = inScalars->GetNumberOfComponents(); + + // Prepare the interpolator + if (this->Interpolator == nullptr) + { + vtkImageInterpolator* interp = vtkImageInterpolator::New(); + interp->SetInterpolationModeToNearest(); + interp->SetTolerance(0.5); + this->Interpolator = interp; + } + this->Interpolator->Initialize(source); + numComponents = this->Interpolator->ComputeNumberOfComponents(numComponents); + + // Create the output scalar array (same type as "Source") + vtkDataArray* scalars = vtkDataArray::CreateDataArray(scalarType); + scalars->SetNumberOfComponents(numComponents); + scalars->SetNumberOfTuples(numPts); + scalars->SetName("ImageScalars"); + + // Create a scalar array for mask + vtkUnsignedCharArray* mask = vtkUnsignedCharArray::New(); + mask->SetNumberOfComponents(1); + mask->SetNumberOfTuples(numPts); + mask->SetName("MaskScalars"); + this->MaskScalars = mask; + + vtkPointData* outPD = output->GetPointData(); + int idx = outPD->AddArray(scalars); + scalars->Delete(); + outPD->SetActiveAttribute(idx, vtkDataSetAttributes::SCALARS); + outPD->AddArray(mask); + mask->Delete(); +} + +//------------------------------------------------------------------------------ +// Thread local storage for the execution of the filter. +struct vtkImageProbeFilter::ProbePointsThreadLocal +{ + ProbePointsThreadLocal() + : BaseThread(false) + { + } + + // Per-thread storage space. + std::vector ThreadStore; + // BaseThread will be set 'true' for thread that gets first piece. + bool BaseThread; +}; + +//------------------------------------------------------------------------------ +// This functor is used by vtkSMPTools, it is called by the threads and, +// in turn, it calls ProbePoints() over a range of points. +class vtkImageProbeFilter::ProbePointsWorklet +{ +public: + ProbePointsWorklet( + vtkImageProbeFilter* probeFilter, vtkDataSet* input, vtkImageData* source, vtkPointData* outPD) + : ProbeFilter(probeFilter) + , Input(input) + , Source(source) + , OutPointData(outPD) + { + } + + void operator()(vtkIdType startId, vtkIdType endId) + { + if (startId == 0) + { + this->Thread.Local().BaseThread = true; + } + this->ProbeFilter->ProbePoints( + this->Input, this->Source, this->OutPointData, startId, endId, &this->Thread.Local()); + } + +private: + vtkImageProbeFilter* ProbeFilter; + vtkDataSet* Input; + vtkImageData* Source; + vtkPointData* OutPointData; + vtkSMPThreadLocal Thread; +}; + +//------------------------------------------------------------------------------ +void vtkImageProbeFilter::DoProbing(vtkDataSet* input, vtkImageData* source, vtkDataSet* output) +{ + vtkDebugMacro(<< "Probing data"); + + vtkPointData* outPD = output->GetPointData(); + + // Estimate the granularity for multithreading + int threads = vtkSMPTools::GetEstimatedNumberOfThreads(); + vtkIdType numPts = input->GetNumberOfPoints(); + vtkIdType grain = numPts / threads; + vtkIdType minGrain = 100; + vtkIdType maxGrain = 1000; + grain = vtkMath::ClampValue(grain, minGrain, maxGrain); + + // Multithread the execution + ProbePointsWorklet worklet(this, input, source, outPD); + vtkSMPTools::For(0, numPts, grain, worklet); +} + +//------------------------------------------------------------------------------ +void vtkImageProbeFilter::Probe(vtkDataSet* input, vtkImageData* source, vtkDataSet* output) +{ + // second stage of attribute initialization: initialize from Input + this->InitializeForProbing(input, source, output); + + // probe the Source at each Input point + this->DoProbing(input, source, output); +} + +//------------------------------------------------------------------------------ +void vtkImageProbeFilter::ProbePoints(vtkDataSet* input, vtkImageData* source, vtkPointData* outPD, + vtkIdType startId, vtkIdType endId, ProbePointsThreadLocal* threadLocal) +{ + // Get information about the pixels type + vtkDataArray* scalars = outPD->GetScalars(); + double minVal = scalars->GetDataTypeMin(); + double maxVal = scalars->GetDataTypeMax(); + int scalarType = scalars->GetDataType(); + int numComp = scalars->GetNumberOfComponents(); + + // Information about the interpolator + vtkAbstractImageInterpolator* interpolator = this->Interpolator; + int numToClamp = numComp; + int numToRound = numComp; + if (scalarType == VTK_FLOAT || scalarType == VTK_DOUBLE) + { + // Only integer data needs clamping or rounding + numToClamp = 0; + numToRound = 0; + } + else + { + vtkImageInterpolator* ii = vtkImageInterpolator::SafeDownCast(interpolator); + if (ii && ii->GetInterpolationMode() == VTK_NEAREST_INTERPOLATION) + { + // Neither clamping nor rounding is used for nearest-neighbor interpolation + numToClamp = 0; + numToRound = 0; + } + else if (ii && ii->GetInterpolationMode() == VTK_LINEAR_INTERPOLATION) + { + // Clamping is only needed for high-order (e.g. cubic, sinc) interpolation. + numToClamp = 0; + } + } + + // We need workspace for pixel computations, use the stack if possible + // or use thread-local storage vectors if pixels have >4 components. + double storage[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + double* value = storage; + double* zeros = storage + 4; + if (numComp > 4) + { + std::vector& storageVec = threadLocal->ThreadStore; + storageVec.resize(numComp * 2, 0); + value = storageVec.data(); + zeros = value + numComp; + } + + // The mask array, says which points were within the image. + unsigned char* mask = this->MaskScalars->GetPointer(0); + + // Loop over all input points, interpolating source data + vtkIdType progressInterval = endId / 20 + 1; + for (vtkIdType ptId = startId; ptId < endId && !GetAbortExecute(); ptId++) + { + if (threadLocal->BaseThread && !(ptId % progressInterval)) + { + // This is not ideal, because if the base thread executes more than one piece, + // then the progress will repeat its 0.0 to 1.0 progression for each piece. + this->UpdateProgress(static_cast(ptId) / endId); + } + + // Get the xyz coordinate of the point in the input dataset + double x[3]; + input->GetPoint(ptId, x); + + // Convert to structured coordinates + double ijk[3]; + source->TransformPhysicalPointToContinuousIndex(x, ijk); + + if (interpolator->CheckBoundsIJK(ijk)) + { + // Do the interpolation + interpolator->InterpolateIJK(ijk, value); + for (int c = 0; c < numToClamp; c++) + { + // Clamping is needed to avoid overlow when output is integer + value[c] = vtkMath::ClampValue(value[c], minVal, maxVal); + } + for (int c = 0; c < numToRound; c++) + { + // This bias results in rounding when SetTuple casts to integer, + // e.g. see implementation of vtkMath::Round() + value[c] += (value[c] > 0.0 ? 0.5 : -0.5); + } + scalars->SetTuple(ptId, value); + mask[ptId] = 1; + } + else + { + // If outside of the image, set to zero + scalars->SetTuple(ptId, zeros); + mask[ptId] = 0; + } + } +} + +//------------------------------------------------------------------------------ +int vtkImageProbeFilter::RequestInformation(vtkInformation* vtkNotUsed(request), + vtkInformationVector** inputVector, vtkInformationVector* outputVector) +{ + // get the info objects + vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation* sourceInfo = inputVector[1]->GetInformationObject(0); + vtkInformation* outInfo = outputVector->GetInformationObject(0); + + // copy extent info from Input to Output + outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), + inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()), 6); + + // copy scalar info from Source to Output + int scalarType = vtkImageData::GetScalarType(sourceInfo); + int numComponents = vtkImageData::GetNumberOfScalarComponents(sourceInfo); + vtkDataObject::SetPointDataActiveScalarInfo(outInfo, scalarType, numComponents); + + return 1; +} + +//------------------------------------------------------------------------------ +int vtkImageProbeFilter::RequestUpdateExtent(vtkInformation* vtkNotUsed(request), + vtkInformationVector** inputVector, vtkInformationVector* outputVector) +{ + // get the info objects + vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation* sourceInfo = inputVector[1]->GetInformationObject(0); + vtkInformation* outInfo = outputVector->GetInformationObject(0); + + // copy update extent from Output to Input + inInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1); + inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), + outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT()), 6); + + // set update extent of Source to its whole extent + sourceInfo->Remove(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT()); + if (sourceInfo->Has(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())) + { + sourceInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), + sourceInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()), 6); + } + + return 1; +} + +//------------------------------------------------------------------------------ +void vtkImageProbeFilter::PrintSelf(ostream& os, vtkIndent indent) +{ + vtkDataObject* source = this->GetSource(); + vtkAbstractImageInterpolator* interpolator = this->GetInterpolator(); + + this->Superclass::PrintSelf(os, indent); + os << indent << "Source: " << source << "\n"; + os << indent << "Interpolator: " << interpolator << "\n"; +} diff --git a/Imaging/Core/vtkImageProbeFilter.h b/Imaging/Core/vtkImageProbeFilter.h new file mode 100644 index 000000000..d90538136 --- /dev/null +++ b/Imaging/Core/vtkImageProbeFilter.h @@ -0,0 +1,126 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: vtkImageProbeFilter.h + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +/** + * @class vtkImageProbeFilter + * @brief sample image values at specified point positions + * + * vtkImageProbeFilter interpolates an image at specified point positions. + * This filter has two inputs: the Input and Source. The Input geometric + * structure is passed through the filter, and the Output point scalars + * are interpolated from the Source image. + * + * This filter can be used to resample an image onto a set of arbitrarily + * placed sample points. For example, if you have a surface data set + * (i.e. a vtkPolyData that has been tesselated so that its points are + * very closely spaced), you can color the polydata from the image points. + * + * In general, this filter is similar to vtkProbeFilter except that the + * Source data is always an image. The advantages that it provides over + * vtkProbeFilter is that it is faster, and it can take advantage of the + * advanced interpolation methods offered by vtkAbstractImageInterpolator + * subclasses. + */ + +#ifndef vtkImageProbeFilter_h +#define vtkImageProbeFilter_h + +#include "vtkDataSetAlgorithm.h" +#include "vtkImagingCoreModule.h" // For export macro + +class vtkAbstractImageInterpolator; +class vtkUnsignedCharArray; +class vtkImageData; +class vtkPointData; + +class VTKIMAGINGCORE_EXPORT vtkImageProbeFilter : public vtkDataSetAlgorithm +{ +public: + static vtkImageProbeFilter* New(); + vtkTypeMacro(vtkImageProbeFilter, vtkDataSetAlgorithm); + void PrintSelf(ostream& os, vtkIndent indent) override; + + //@{ + /** + * Specify the data set that will be probed at the input points. + * The Input gives the geometry (the points and cells) for the output, + * while the Source is probed (interpolated) to generate the scalars, + * vectors, etc. for the output points based on the point locations. + */ + void SetSourceData(vtkDataObject* source); + vtkDataObject* GetSource(); + //@} + + /** + * Specify the data set that will be probed at the input points. + * The Input gives the geometry (the points and cells) for the output, + * while the Source is probed (interpolated) to generate the scalars, + * vectors, etc. for the output points based on the point locations. + */ + void SetSourceConnection(vtkAlgorithmOutput* algOutput); + + //@{ + /** + * Set the interpolator to use. If this is not set, then nearest-neighbor + * interpolation will be used, with the tolerance of the interpolator set + * to 0.5 (half the voxel size). + */ + virtual void SetInterpolator(vtkAbstractImageInterpolator* interpolator); + virtual vtkAbstractImageInterpolator* GetInterpolator() { return this->Interpolator; } + //@} + +protected: + vtkImageProbeFilter(); + ~vtkImageProbeFilter() override; + + int FillInputPortInformation(int port, vtkInformation* info) override; + + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + int RequestUpdateExtent(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + + /** + * Equivalent to calling InitializeForProbing(); DoProbing(). + */ + void Probe(vtkDataSet* input, vtkImageData* source, vtkDataSet* output); + + /** + * Initialize the interpolator and the output arrays. + */ + virtual void InitializeForProbing(vtkDataSet* input, vtkImageData* source, vtkDataSet* output); + + /** + * Probe appropriate points (InitializeForProbing() must be called first). + */ + void DoProbing(vtkDataSet* input, vtkImageData* source, vtkDataSet* output); + + vtkAbstractImageInterpolator* Interpolator; + vtkUnsignedCharArray* MaskScalars; + +private: + vtkImageProbeFilter(const vtkImageProbeFilter&) = delete; + void operator=(const vtkImageProbeFilter&) = delete; + + class ProbePointsWorklet; + struct ProbePointsThreadLocal; + + /** + * This method is called from the work threads if SMP is used, or called + * from the main thread if SMP is not used. + */ + void ProbePoints(vtkDataSet* input, vtkImageData* source, vtkPointData* outPD, vtkIdType startId, + vtkIdType endId, ProbePointsThreadLocal* threadLocal); +}; + +#endif diff --git a/Imaging/Core/vtkImageResample.cxx b/Imaging/Core/vtkImageResample.cxx index eec6cd351..47862cdbd 100644 --- a/Imaging/Core/vtkImageResample.cxx +++ b/Imaging/Core/vtkImageResample.cxx @@ -197,7 +197,7 @@ int vtkImageResample::RequestInformation(vtkInformation* vtkNotUsed(request), outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), ext, 6); outInfo->Set(vtkDataObject::SPACING(), spacing, 3); - return 1; + return this->RequestInformationBase(inputVector, outputVector); } void vtkImageResample::PrintSelf(ostream& os, vtkIndent indent) diff --git a/Imaging/Core/vtkImageReslice.cxx b/Imaging/Core/vtkImageReslice.cxx index c4ca4ca8d..a30d7a8e2 100644 --- a/Imaging/Core/vtkImageReslice.cxx +++ b/Imaging/Core/vtkImageReslice.cxx @@ -491,7 +491,9 @@ vtkAbstractImageInterpolator* vtkImageReslice::GetInterpolator() { if (this->Interpolator == nullptr) { - this->Interpolator = vtkImageInterpolator::New(); + vtkImageInterpolator* i = vtkImageInterpolator::New(); + i->SetInterpolationMode(this->InterpolationMode); + this->Interpolator = i; } return this->Interpolator; @@ -1085,9 +1087,26 @@ int vtkImageReslice::RequestInformation(vtkInformation* vtkNotUsed(request), outInfo->Set(vtkDataObject::SPACING(), outSpacing, 3); outInfo->Set(vtkDataObject::ORIGIN(), outOrigin, 3); + return this->RequestInformationBase(inputVector, outputVector); +} + +//------------------------------------------------------------------------------ +int vtkImageReslice::RequestInformationBase( + vtkInformationVector** inputVector, vtkInformationVector* outputVector) +{ + vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation* outInfo = outputVector->GetInformationObject(0); vtkInformation* outStencilInfo = outputVector->GetInformationObject(1); + + int outWholeExt[6]; + outInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), outWholeExt); + if (this->GenerateStencilOutput) { + double outSpacing[3], outOrigin[3]; + outInfo->Get(vtkDataObject::SPACING(), outSpacing); + outInfo->Get(vtkDataObject::ORIGIN(), outOrigin); + outStencilInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), outWholeExt, 6); outStencilInfo->Set(vtkDataObject::SPACING(), outSpacing, 3); outStencilInfo->Set(vtkDataObject::ORIGIN(), outOrigin, 3); diff --git a/Imaging/Core/vtkImageReslice.h b/Imaging/Core/vtkImageReslice.h index b8417978d..f5e71bbfe 100644 --- a/Imaging/Core/vtkImageReslice.h +++ b/Imaging/Core/vtkImageReslice.h @@ -562,6 +562,13 @@ protected: inPtr, outPtr, inputType, inputNumComponents, count, idX, idY, idZ, threadId); } + /** + * For derived classes, this should be called at the very end of + * RequestInformation() to ensure that various bit and pieces of + * state information are correctly set prior to execution. + */ + int RequestInformationBase(vtkInformationVector**, vtkInformationVector*); + void GetAutoCroppedOutputBounds(vtkInformation* inInfo, double bounds[6]); void AllocateOutputData(vtkImageData* output, vtkInformation* outInfo, int* uExtent) override; vtkImageData* AllocateOutputData(vtkDataObject*, vtkInformation*) override; diff --git a/Parallel/Core/vtkPSystemTools.cxx b/Parallel/Core/vtkPSystemTools.cxx index 2d91bdbb3..91878260b 100644 --- a/Parallel/Core/vtkPSystemTools.cxx +++ b/Parallel/Core/vtkPSystemTools.cxx @@ -152,13 +152,13 @@ bool vtkPSystemTools::FindProgramPath(const char* argv0, std::string& pathOut, } //---------------------------------------------------------------------------- -std::string vtkPSystemTools::GetCurrentWorkingDirectory(bool collapse) +std::string vtkPSystemTools::GetCurrentWorkingDirectory(bool /* collapse */) { vtkMultiProcessController* controller = vtkMultiProcessController::GetGlobalController(); std::string returnString; if (controller->GetLocalProcessId() == 0) { - returnString = vtksys::SystemTools::GetCurrentWorkingDirectory(collapse); + returnString = vtksys::SystemTools::GetCurrentWorkingDirectory(); } vtkPSystemTools::BroadcastString(returnString, 0); return returnString; diff --git a/Remote/vtkDICOM.remote.cmake b/Remote/vtkDICOM.remote.cmake index 6c316ed36..e08ca31c9 100644 --- a/Remote/vtkDICOM.remote.cmake +++ b/Remote/vtkDICOM.remote.cmake @@ -5,6 +5,6 @@ vtk_fetch_module(vtkDICOM "Dicom classes and utilities" GIT_REPOSITORY https://github.com/dgobbi/vtk-dicom - # vtk-dicom release 8.9.12 plus warning and build fixes - GIT_TAG d15c9b9100ff1df6caca8cc1073b121cb234396c + # vtk-dicom release 0.8.12 plus bug fixes + GIT_TAG 324057367c4c1390ed51f0a9bc2000c254d4e811 ) diff --git a/Rendering/Annotation/vtkAxesActor.cxx b/Rendering/Annotation/vtkAxesActor.cxx index ff4493563..088e9564b 100644 --- a/Rendering/Annotation/vtkAxesActor.cxx +++ b/Rendering/Annotation/vtkAxesActor.cxx @@ -31,6 +31,9 @@ #include "vtkTextProperty.h" #include "vtkTransform.h" +#include +#include + vtkStandardNewMacro(vtkAxesActor); vtkCxxSetObjectMacro(vtkAxesActor, UserDefinedTip, vtkPolyData); @@ -344,56 +347,27 @@ void vtkAxesActor::GetBounds(double bounds[6]) // Get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax). double* vtkAxesActor::GetBounds() { - double bounds[6]; - int i; - - this->XAxisShaft->GetBounds(this->Bounds); - - this->YAxisShaft->GetBounds(bounds); - for (i = 0; i < 3; ++i) - { - this->Bounds[2 * i + 1] = (bounds[2 * i + 1] > this->Bounds[2 * i + 1]) - ? (bounds[2 * i + 1]) - : (this->Bounds[2 * i + 1]); - } - - this->ZAxisShaft->GetBounds(bounds); - for (i = 0; i < 3; ++i) - { - this->Bounds[2 * i + 1] = (bounds[2 * i + 1] > this->Bounds[2 * i + 1]) - ? (bounds[2 * i + 1]) - : (this->Bounds[2 * i + 1]); - } + vtkProp3D* part[6] = { this->XAxisShaft, this->YAxisShaft, this->ZAxisShaft, this->XAxisTip, + this->YAxisTip, this->ZAxisTip }; - this->XAxisTip->GetBounds(bounds); - for (i = 0; i < 3; ++i) - { - this->Bounds[2 * i + 1] = (bounds[2 * i + 1] > this->Bounds[2 * i + 1]) - ? (bounds[2 * i + 1]) - : (this->Bounds[2 * i + 1]); - } - - this->YAxisTip->GetBounds(bounds); - for (i = 0; i < 3; ++i) - { - this->Bounds[2 * i + 1] = (bounds[2 * i + 1] > this->Bounds[2 * i + 1]) - ? (bounds[2 * i + 1]) - : (this->Bounds[2 * i + 1]); - } - - this->ZAxisTip->GetBounds(bounds); - for (i = 0; i < 3; ++i) + // We want this actor to rotate / re-center about the origin, so give it + // the bounds it would have if the axes were symmetric. + double maxbounds[3] = { 0.0, 0.0, 0.0 }; + double bounds[6]; + for (int j = 0; j < 6; ++j) { - this->Bounds[2 * i + 1] = (bounds[2 * i + 1] > this->Bounds[2 * i + 1]) - ? (bounds[2 * i + 1]) - : (this->Bounds[2 * i + 1]); + part[j]->GetBounds(bounds); + for (int i = 0; i < 3; ++i) + { + maxbounds[i] = std::max(maxbounds[i], std::fabs(bounds[2 * i])); + maxbounds[i] = std::max(maxbounds[i], std::fabs(bounds[2 * i + 1])); + } } - // We want this actor to rotate / re-center about the origin, so give it - // the bounds it would have if the axes were symmetric. - for (i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { - this->Bounds[2 * i] = -this->Bounds[2 * i + 1]; + this->Bounds[2 * i + 1] = maxbounds[i]; + this->Bounds[2 * i] = -maxbounds[i]; } return this->Bounds; diff --git a/Rendering/ContextOpenGL2/vtk.module b/Rendering/ContextOpenGL2/vtk.module index 31e647ac5..6fc09752c 100644 --- a/Rendering/ContextOpenGL2/vtk.module +++ b/Rendering/ContextOpenGL2/vtk.module @@ -4,6 +4,8 @@ LIBRARY_NAME vtkRenderingContextOpenGL2 KIT VTK::OpenGL +GROUPS + Rendering IMPLEMENTS VTK::RenderingContext2D DEPENDS diff --git a/Rendering/Core/Testing/Cxx/TestCompositePolyDataMapper2MixedGeometryCellScalars.cxx b/Rendering/Core/Testing/Cxx/TestCompositePolyDataMapper2MixedGeometryCellScalars.cxx index 57c195f95..6c5d1925a 100644 --- a/Rendering/Core/Testing/Cxx/TestCompositePolyDataMapper2MixedGeometryCellScalars.cxx +++ b/Rendering/Core/Testing/Cxx/TestCompositePolyDataMapper2MixedGeometryCellScalars.cxx @@ -165,9 +165,9 @@ int TestCompositePolyDataMapper2MixedGeometryCellScalars(int argc, char* argv[]) // modify the data to force a rebuild of OpenGL structs // after rendering set one cylinder to white - mapper->SetBlockColor(40, 1.0, 1.0, 1.0); - mapper->SetBlockOpacity(40, 1.0); - mapper->SetBlockVisibility(40, 1.0); + mapper->SetBlockColor(54, 1.0, 1.0, 1.0); + mapper->SetBlockOpacity(54, 1.0); + mapper->SetBlockVisibility(54, 1.0); timer->StartTimer(); win->Render(); @@ -180,9 +180,9 @@ int TestCompositePolyDataMapper2MixedGeometryCellScalars(int argc, char* argv[]) for (int i = 0; i <= numFrames; i++) { ren->GetActiveCamera()->Elevation(15.0 / numFrames); - ren->GetActiveCamera()->Azimuth(-130.0 / numFrames); - ren->GetActiveCamera()->Zoom(pow(1.6, 1.0 / numFrames)); - ren->GetActiveCamera()->Roll(0.0 / numFrames); + ren->GetActiveCamera()->Azimuth(-190.0 / numFrames); + ren->GetActiveCamera()->Zoom(pow(1.5, 1.0 / numFrames)); + ren->GetActiveCamera()->Roll(5.0 / numFrames); win->Render(); } diff --git a/Rendering/Core/Testing/Cxx/TestCompositePolyDataMapper2MixedGeometryEdges.cxx b/Rendering/Core/Testing/Cxx/TestCompositePolyDataMapper2MixedGeometryEdges.cxx index 408c028ed..b0c0e6383 100644 --- a/Rendering/Core/Testing/Cxx/TestCompositePolyDataMapper2MixedGeometryEdges.cxx +++ b/Rendering/Core/Testing/Cxx/TestCompositePolyDataMapper2MixedGeometryEdges.cxx @@ -165,9 +165,9 @@ int TestCompositePolyDataMapper2MixedGeometryEdges(int argc, char* argv[]) // modify the data to force a rebuild of OpenGL structs // after rendering set one cylinder to white - mapper->SetBlockColor(40, 1.0, 1.0, 1.0); - mapper->SetBlockOpacity(40, 1.0); - mapper->SetBlockVisibility(40, 1.0); + mapper->SetBlockColor(54, 1.0, 1.0, 1.0); + mapper->SetBlockOpacity(54, 1.0); + mapper->SetBlockVisibility(54, 1.0); timer->StartTimer(); win->Render(); @@ -180,9 +180,9 @@ int TestCompositePolyDataMapper2MixedGeometryEdges(int argc, char* argv[]) for (int i = 0; i <= numFrames; i++) { ren->GetActiveCamera()->Elevation(15.0 / numFrames); - ren->GetActiveCamera()->Azimuth(-130.0 / numFrames); - ren->GetActiveCamera()->Zoom(pow(1.6, 1.0 / numFrames)); - ren->GetActiveCamera()->Roll(0.0 / numFrames); + ren->GetActiveCamera()->Azimuth(-190.0 / numFrames); + ren->GetActiveCamera()->Zoom(pow(1.5, 1.0 / numFrames)); + ren->GetActiveCamera()->Roll(5.0 / numFrames); win->Render(); } diff --git a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2.png.sha512 b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2.png.sha512 index 67056817d..80f7a6462 100644 --- a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2.png.sha512 +++ b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2.png.sha512 @@ -1 +1 @@ -c8847c00475ef73475967ded5eed0d0889253d329e47d60439089700b21a666ad1a2312d0bd55b42ff6ecc524ec2a94f07bd6513b823ec60f1c2efec00cdcb4a +26a26f9b482ece1b1f847d235dce6591a0f74ecfcf808f23bf672b094cbc7e61efb7ce1fa29aae7adab41c2884f70fe1de0769cdf41b640ebeea80de26a3d565 diff --git a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2CellScalars.png.sha512 b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2CellScalars.png.sha512 index b0bf6093d..1bd5d2744 100644 --- a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2CellScalars.png.sha512 +++ b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2CellScalars.png.sha512 @@ -1 +1 @@ -3c0f5b89defe28e0a194cf67ee42d82e664f93888373e6c0f6329e01765216c547ec03c6137d7b3c75630e0b2981e90b03bafba5216c33f672bfc89175c4300b +177a7a65d5c9ed9a5258b0e01aefe935bc2f8bbe6b2c614c127ca84ecb6929b7029845a099a41b9047c1efaaf2c09e9d892bcfc108fe827bc19e74dc518cf52f diff --git a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2MixedGeometryCellScalars.png.sha512 b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2MixedGeometryCellScalars.png.sha512 index 2e2ce3e9e..c56a03e1f 100644 --- a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2MixedGeometryCellScalars.png.sha512 +++ b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2MixedGeometryCellScalars.png.sha512 @@ -1 +1 @@ -ebc6e64968ac8b90f20ac27fd460d95fca692411ffac6c65b0f9ba89958060c75a221d01266a4d2f784e32d555b9e1fbbdfea1c560fefa0ebcc2e7fbc241b962 +59479a0a8eddf76f4ae21118194029dfa8c44dbef81755558fb7f3f73eaa70f062cabcea1d9f0f14cdd6dec958ceb025005ad0baecd28627c6dbb58b4e3929b0 diff --git a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2MixedGeometryEdges.png.sha512 b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2MixedGeometryEdges.png.sha512 index b9e3f847c..714e3a184 100644 --- a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2MixedGeometryEdges.png.sha512 +++ b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2MixedGeometryEdges.png.sha512 @@ -1 +1 @@ -c953c2d33cbe54b660b8466d7b21ac62aba358c14090b8d24471308835bab37b391dc6dcb1738839c5669fb1d64e2acd249e148e2757050b0cb1da29871d97fd +5e2ccb83f59d707af4e684ba36706f80f389508b92b3bec04bd5792eaa56968b697951b9eb75d1b6ccf66b21226d3cf200e80dcdf5c9272489e9b14a130dca32 diff --git a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2Picking.png.sha512 b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2Picking.png.sha512 index 5eab3179e..815ecd3e8 100644 --- a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2Picking.png.sha512 +++ b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2Picking.png.sha512 @@ -1 +1 @@ -bde7376a2a94383bfc0a48f4a0679b5e026863a5bcad96f542994eb6c8aa11d56826fb8bd423a30b8c6f7dfb32b3b2b320a32aa51698e81b1a6879fe42aea397 +fb4ca4b6fa5cc5a19742c11ed21cf2b94e22624d456e2379a7dd4c8ef7230510e30c287d215b88adcc4a1a309846c1ad5ff5b602db0197b44549860fb64f8794 diff --git a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2Scalars.png.sha512 b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2Scalars.png.sha512 index c06c402b4..df284ab43 100644 --- a/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2Scalars.png.sha512 +++ b/Rendering/Core/Testing/Data/Baseline/TestCompositePolyDataMapper2Scalars.png.sha512 @@ -1 +1 @@ -8f8a19e439734e12fd89b0965dc03be71b1f32838660fbd48d98d67d2152d4aa788d5e0a69374d057f87a59e9db12479aede7bd2ae6ea93720c6d24fb5dc75ab +e045b00ec033132a80fa3200e24eb84dfc63e9a63d2698b5ae916cbe0e19915a581e47a848e8d2718c3c98aa12979c63c246aa356e7bff6e75c3a58044079474 diff --git a/Rendering/Core/vtkCompositeDataDisplayAttributes.cxx b/Rendering/Core/vtkCompositeDataDisplayAttributes.cxx index 4c2c392cf..640e995db 100644 --- a/Rendering/Core/vtkCompositeDataDisplayAttributes.cxx +++ b/Rendering/Core/vtkCompositeDataDisplayAttributes.cxx @@ -375,10 +375,6 @@ vtkDataObject* vtkCompositeDataDisplayAttributes::DataObjectFromIndex( return data; } } - else - { - ++current_flat_index; - } } } diff --git a/Rendering/Core/vtkWindowLevelLookupTable.cxx b/Rendering/Core/vtkWindowLevelLookupTable.cxx index bc6e19750..6a4e57b42 100644 --- a/Rendering/Core/vtkWindowLevelLookupTable.cxx +++ b/Rendering/Core/vtkWindowLevelLookupTable.cxx @@ -42,46 +42,43 @@ vtkWindowLevelLookupTable::vtkWindowLevelLookupTable(int sze, int ext) //---------------------------------------------------------------------------- // Table is built as a linear ramp between MinimumTableValue and // MaximumTableValue. -void vtkWindowLevelLookupTable::Build() +void vtkWindowLevelLookupTable::ForceBuild() { - if (this->Table->GetNumberOfTuples() < 1 || - (this->GetMTime() > this->BuildTime && this->InsertTime < this->BuildTime)) - { - int i, j; - unsigned char* rgba; - double start[4], incr[4]; + double start[4], incr[4]; - for (j = 0; j < 4; j++) - { - start[j] = this->MinimumTableValue[j] * 255; - incr[j] = ((this->MaximumTableValue[j] - this->MinimumTableValue[j]) / - (this->NumberOfColors - 1) * 255); - } + for (int j = 0; j < 4; j++) + { + start[j] = this->MinimumTableValue[j] * 255; + incr[j] = ((this->MaximumTableValue[j] - this->MinimumTableValue[j]) / + (this->NumberOfColors - 1) * 255); + } - if (this->InverseVideo) + if (this->InverseVideo) + { + for (vtkIdType i = 0; i < this->NumberOfColors; i++) { - for (i = 0; i < this->NumberOfColors; i++) + unsigned char* rgba = this->Table->WritePointer(4 * i, 4); + for (int j = 0; j < 4; j++) { - rgba = this->Table->WritePointer(4 * i, 4); - for (j = 0; j < 4; j++) - { - rgba[j] = - static_cast(start[j] + (this->NumberOfColors - i - 1) * incr[j] + 0.5); - } + rgba[j] = + static_cast(start[j] + (this->NumberOfColors - i - 1) * incr[j] + 0.5); } } - else + } + else + { + for (vtkIdType i = 0; i < this->NumberOfColors; i++) { - for (i = 0; i < this->NumberOfColors; i++) + unsigned char* rgba = this->Table->WritePointer(4 * i, 4); + for (int j = 0; j < 4; j++) { - rgba = this->Table->WritePointer(4 * i, 4); - for (j = 0; j < 4; j++) - { - rgba[j] = static_cast(start[j] + i * incr[j] + 0.5); - } + rgba[j] = static_cast(start[j] + i * incr[j] + 0.5); } } } + + this->BuildSpecialColors(); + this->BuildTime.Modified(); } diff --git a/Rendering/Core/vtkWindowLevelLookupTable.h b/Rendering/Core/vtkWindowLevelLookupTable.h index 56cf58cbb..0f0dacfb4 100644 --- a/Rendering/Core/vtkWindowLevelLookupTable.h +++ b/Rendering/Core/vtkWindowLevelLookupTable.h @@ -50,7 +50,7 @@ public: * Generate lookup table as a linear ramp between MinimumTableValue * and MaximumTableValue. */ - void Build() override; + void ForceBuild() override; //@{ /** diff --git a/Rendering/FreeType/vtkFreeTypeTools.cxx b/Rendering/FreeType/vtkFreeTypeTools.cxx index c54289dc6..03b899c4d 100644 --- a/Rendering/FreeType/vtkFreeTypeTools.cxx +++ b/Rendering/FreeType/vtkFreeTypeTools.cxx @@ -378,8 +378,7 @@ FTC_CMapCache* vtkFreeTypeTools::GetCMapCache() } //---------------------------------------------------------------------------- -FT_CALLBACK_DEF(FT_Error) -vtkFreeTypeToolsFaceRequester( +static FT_Error vtkFreeTypeToolsFaceRequester( FTC_FaceID face_id, FT_Library lib, FT_Pointer request_data, FT_Face* face) { #if VTK_FTFC_DEBUG_CD diff --git a/Rendering/FreeTypeFontConfig/vtkFontConfigFreeTypeTools.cxx b/Rendering/FreeTypeFontConfig/vtkFontConfigFreeTypeTools.cxx index 5c1908cf2..818ff058b 100644 --- a/Rendering/FreeTypeFontConfig/vtkFontConfigFreeTypeTools.cxx +++ b/Rendering/FreeTypeFontConfig/vtkFontConfigFreeTypeTools.cxx @@ -29,8 +29,7 @@ vtkStandardNewMacro(vtkFontConfigFreeTypeTools); namespace { // The FreeType face requester callback: -FT_CALLBACK_DEF(FT_Error) -vtkFontConfigFreeTypeToolsFaceRequester( +static FT_Error vtkFontConfigFreeTypeToolsFaceRequester( FTC_FaceID face_id, FT_Library lib, FT_Pointer request_data, FT_Face* face) { // Get a pointer to the current vtkFontConfigFreeTypeTools object diff --git a/Rendering/GL2PSOpenGL2/Testing/Cxx/CMakeLists.txt b/Rendering/GL2PSOpenGL2/Testing/Cxx/CMakeLists.txt index 3d26deed5..10749ec74 100644 --- a/Rendering/GL2PSOpenGL2/Testing/Cxx/CMakeLists.txt +++ b/Rendering/GL2PSOpenGL2/Testing/Cxx/CMakeLists.txt @@ -14,6 +14,6 @@ vtk_add_gl2ps_test_cxx(${GL2PSTests}) # Compile the PNGCompare test, which is used to validate PNG images (read from # disk, not generated in VTK). -list(APPEND tests PNGCompare) +list(APPEND tests PNGCompare.cxx) vtk_test_cxx_executable(vtkRenderingGL2PSOpenGL2CxxTests tests RENDERING_FACTORY) diff --git a/Rendering/OpenGL2/Testing/Cxx/TestCompositePolyDataMapper2Spheres.cxx b/Rendering/OpenGL2/Testing/Cxx/TestCompositePolyDataMapper2Spheres.cxx index 5e601d44f..5d48a8fc6 100644 --- a/Rendering/OpenGL2/Testing/Cxx/TestCompositePolyDataMapper2Spheres.cxx +++ b/Rendering/OpenGL2/Testing/Cxx/TestCompositePolyDataMapper2Spheres.cxx @@ -101,17 +101,17 @@ int TestCompositePolyDataMapper2Spheres(int argc, char* argv[]) blocks[parent]->SetBlock(block, (block % 2) ? nullptr : child.GetPointer()); blocks[parent]->GetMetaData(block)->Set(vtkCompositeDataSet::NAME(), blockName.c_str()); // test not setting it on some - if (block % 11) + if (block % 7) { double r, g, b; - vtkMath::HSVToRGB(0.8 * block / nblocks, 0.2 + 0.8 * ((parent - levelStart) % 8) / 7.0, + vtkMath::HSVToRGB(0.8 * block / nblocks, 0.2 + 0.8 * ((parent - levelStart) % 4) / 3.0, 1.0, &r, &g, &b); mapper->SetBlockColor(parent + numLeaves + 1, r, g, b); - mapper->SetBlockVisibility(parent + numLeaves, (block % 7) != 0); + mapper->SetBlockVisibility(parent + numLeaves, (block % 3) != 0); vtkMath::HSVToRGB(0.2 + 0.8 * block / nblocks, - 0.7 + 0.3 * ((parent - levelStart) % 8) / 7.0, 1.0, &r, &g, &b); + 0.7 + 0.3 * ((parent - levelStart) % 4) / 3.0, 1.0, &r, &g, &b); mapper2->SetBlockColor(parent + numLeaves + 1, r, g, b); - mapper2->SetBlockVisibility(parent + numLeaves, (block % 7) != 0); + mapper2->SetBlockVisibility(parent + numLeaves, (block % 3) != 0); } ++numLeaves; } diff --git a/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Spheres.png.sha512 b/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Spheres.png.sha512 index 5babca05b..0e3ac5972 100644 --- a/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Spheres.png.sha512 +++ b/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Spheres.png.sha512 @@ -1 +1 @@ -653fd577fdbbf71e3c08587617a88d95601e57ff5e4654300d0448b59c6cb226e43e4bb5c12380f3805c1c237f3b77b03746d4e6186fbed64f8f4f9c75d86fb1 +5f0ba78fe7d54bc7747e3305639343b12e2d2c789f9ea5c6e90a1cc1fc05568acbd384699e5391f533328f33aba38d4256c0667fc029704b60c5c60b2ba633bd diff --git a/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Spheres_1.png.sha512 b/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Spheres_1.png.sha512 new file mode 100644 index 000000000..92840cb7a --- /dev/null +++ b/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Spheres_1.png.sha512 @@ -0,0 +1 @@ +898a87a22a8d1c009484a6127cdff8f4055542e60ce5836c737bd549d4f97af1a9fa110ae54a20148f054f3fdd37c982fa1111291e0fb598fab9d55f4e64c1c8 diff --git a/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Vertices.png.sha512 b/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Vertices.png.sha512 index 3e1c44bc1..1fea385b6 100644 --- a/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Vertices.png.sha512 +++ b/Rendering/OpenGL2/Testing/Data/Baseline/TestCompositePolyDataMapper2Vertices.png.sha512 @@ -1 +1 @@ -5372aeed03ac6342df4002c4eafe2e4cd4c73d01cde2e70cdbb36a90241970c779785831a398918293225e3ae4d8c3780f848875cfb6cde101f4b9bb6360c037 +9747ee126aa106d60ebfd747828390ba4a7ff0a271cf54d920a1606bc3eb40ef1380c219e5987d8dc4c3fdb77ed86dc80a68442dfc7410aacdee7d966f23a348 diff --git a/Rendering/OpenGL2/vtk.module b/Rendering/OpenGL2/vtk.module index 09cd0eec0..c4d11e999 100644 --- a/Rendering/OpenGL2/vtk.module +++ b/Rendering/OpenGL2/vtk.module @@ -5,6 +5,8 @@ LIBRARY_NAME IMPLEMENTABLE KIT VTK::OpenGL +GROUPS + Rendering IMPLEMENTS VTK::RenderingCore DEPENDS diff --git a/Rendering/OpenGL2/vtkCocoaGLView.mm b/Rendering/OpenGL2/vtkCocoaGLView.mm index 98629be69..3742f0955 100644 --- a/Rendering/OpenGL2/vtkCocoaGLView.mm +++ b/Rendering/OpenGL2/vtkCocoaGLView.mm @@ -21,6 +21,7 @@ #import "vtkCocoaRenderWindowInteractor.h" #import "vtkCommand.h" #import "vtkNew.h" +#import "vtkOpenGLState.h" #import "vtkStringArray.h" //---------------------------------------------------------------------------- @@ -125,6 +126,10 @@ if (_myVTKRenderWindow && _myVTKRenderWindow->GetMapped()) { + vtkOpenGLState* state = _myVTKRenderWindow->GetState(); + state->ResetGLScissorState(); + vtkOpenGLState::ScopedglScissor ss(state); + _myVTKRenderWindow->Render(); } } diff --git a/Rendering/OpenGL2/vtkCocoaRenderWindow.mm b/Rendering/OpenGL2/vtkCocoaRenderWindow.mm index cb1c3d717..dd480d2fb 100644 --- a/Rendering/OpenGL2/vtkCocoaRenderWindow.mm +++ b/Rendering/OpenGL2/vtkCocoaRenderWindow.mm @@ -385,7 +385,10 @@ bool vtkCocoaRenderWindow::IsDrawable() // then check that the drawable is valid NSOpenGLContext* context = (NSOpenGLContext*)this->GetContextId(); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" bool ok = [context view] != nil; +#pragma clang diagnostic pop return win && ok; } @@ -846,7 +849,10 @@ void vtkCocoaRenderWindow::CreateAWindow() // SetParentId() was added for) then the Tk superview handles the events. NSRect glRect = NSMakeRect(x, y, width, height); NSView* glView = [[NSView alloc] initWithFrame:glRect]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [glView setWantsBestResolutionOpenGLSurface:wantsBest]; +#pragma clang diagnostic pop [parent addSubview:glView]; this->SetWindowId(glView); this->ViewCreated = 1; @@ -866,7 +872,10 @@ void vtkCocoaRenderWindow::CreateAWindow() // Create a vtkCocoaGLView. vtkCocoaGLView* glView = [[vtkCocoaGLView alloc] initWithFrame:viewRect]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [glView setWantsBestResolutionOpenGLSurface:wantsBest]; +#pragma clang diagnostic pop [window setContentView:glView]; // We have to set the frame's view rect again to work around rounding // that occurs when setting the window's content view. @@ -887,7 +896,10 @@ void vtkCocoaRenderWindow::CreateAWindow() if (connectContextToNSView) { NSView* view = (NSView*)this->GetWindowId(); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [context setView:view]; +#pragma clang diagnostic pop } // the error "invalid drawable" in the console from this call can appear @@ -1009,7 +1021,10 @@ void vtkCocoaRenderWindow::CreateGLContext() // This syncs the OpenGL context to the VBL to prevent tearing GLint one = 1; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [context setValues:&one forParameter:NSOpenGLCPSwapInterval]; +#pragma clang diagnostic pop } this->SetPixelFormat((void*)pixelFormat); @@ -1045,7 +1060,10 @@ void vtkCocoaRenderWindow::Start() if (connectContextToNSView) { NSView* view = (NSView*)this->GetWindowId(); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [context setView:view]; +#pragma clang diagnostic pop } // the error "invalid drawable" in the console from this call can appear diff --git a/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx b/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx index 9bbbc2ba5..edb902311 100644 --- a/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx +++ b/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx @@ -1805,6 +1805,21 @@ int vtkOpenGLRenderWindow::CreateOffScreenFramebuffer(int width, int height) assert("pre: positive_width" && width > 0); assert("pre: positive_height" && height > 0); +#if defined(__APPLE__) + // make sure requested multisamples is OK with platform + // APPLE Intel systems seem to have buggy multisampled + // frambuffer blits etc that cause issues + if (this->MultiSamples > 0) + { + char const* tmp = reinterpret_cast(::glGetString(GL_VENDOR)); + std::string vendor = tmp ? tmp : std::string(); + if (vendor.find("Intel") != std::string::npos) + { + this->MultiSamples = 0; + } + } +#endif + if (this->LastMultiSamples != this->MultiSamples) { this->OffScreenFramebuffer->ReleaseGraphicsResources(this); diff --git a/Rendering/RayTracing/Testing/Data/Baseline/TestOSPRayCompositePolyDataMapper2.png.sha512 b/Rendering/RayTracing/Testing/Data/Baseline/TestOSPRayCompositePolyDataMapper2.png.sha512 index a45e8bb41..3e0f760d7 100644 --- a/Rendering/RayTracing/Testing/Data/Baseline/TestOSPRayCompositePolyDataMapper2.png.sha512 +++ b/Rendering/RayTracing/Testing/Data/Baseline/TestOSPRayCompositePolyDataMapper2.png.sha512 @@ -1 +1 @@ -dc15c4fbead617b6ac1336568db4a1822f1cad30a94d073e30fb370d0407fc59d2e08c21646f63aaae5c7c185ce827cfeff8e5567eb655e8011156c473cc9b92 +1170a364b05794549c302d78279dbf7681dd4041820ff15a07ef67341e7e5a03767964b867fde2ad76627a565374405b9a7ce118b8497429d8d04aaaf8bdd296 diff --git a/Rendering/RayTracing/vtkOSPRayPass.cxx b/Rendering/RayTracing/vtkOSPRayPass.cxx index 6c1c5ef68..fbd61ef07 100644 --- a/Rendering/RayTracing/vtkOSPRayPass.cxx +++ b/Rendering/RayTracing/vtkOSPRayPass.cxx @@ -40,6 +40,11 @@ #include "RTWrapper/RTWrapper.h" +#ifdef __APPLE__ +#include +#include +#endif + class vtkOSPRayPassInternals : public vtkRenderPass { public: @@ -165,6 +170,10 @@ vtkOSPRayPass::~vtkOSPRayPass() // ---------------------------------------------------------------------------- void vtkOSPRayPass::RTInit() { + if (!vtkOSPRayPass::IsSupported()) + { + return; + } if (RTDeviceRefCount == 0) { rtwInit(); @@ -175,6 +184,10 @@ void vtkOSPRayPass::RTInit() // ---------------------------------------------------------------------------- void vtkOSPRayPass::RTShutdown() { + if (!vtkOSPRayPass::IsSupported()) + { + return; + } --RTDeviceRefCount; if (RTDeviceRefCount == 0) { @@ -194,6 +207,17 @@ vtkCxxSetObjectMacro(vtkOSPRayPass, SceneGraph, vtkOSPRayRendererNode); // ---------------------------------------------------------------------------- void vtkOSPRayPass::Render(const vtkRenderState* s) { + if (!vtkOSPRayPass::IsSupported()) + { + static bool warned = false; + if (!warned) + { + vtkWarningMacro(<< "Ignoring render request because OSPRay is not supported."); + warned = true; + } + return; + } + vtkRenderer* ren = s->GetRenderer(); if (ren) { @@ -217,6 +241,17 @@ void vtkOSPRayPass::Render(const vtkRenderState* s) // ---------------------------------------------------------------------------- void vtkOSPRayPass::RenderInternal(const vtkRenderState* s) { + if (!vtkOSPRayPass::IsSupported()) + { + static bool warned = false; + if (!warned) + { + vtkWarningMacro(<< "Ignoring render request because OSPRay is not supported."); + warned = true; + } + return; + } + this->NumberOfRenderedProps = 0; if (this->SceneGraph) @@ -362,9 +397,65 @@ void vtkOSPRayPass::RenderInternal(const vtkRenderState* s) } } +// ---------------------------------------------------------------------------- +bool vtkOSPRayPass::IsSupported() +{ + static bool detected = false; + static bool is_supported = true; + + // Short-circuit to avoid querying on every call. + if (detected) + { + return is_supported; + } + + ////////////////////////////////////////////////////////////////////////////// + // Note that this class is used for OSPRay and OptiX (in addition to any + // other RayTracing backends). Currently the only "spoiling" detection is + // Apple's Rosetta. Since the only other backend is OptiX today and is not + // supported on macOS within VTK anyways, there is no conflict. + ////////////////////////////////////////////////////////////////////////////// + +#ifdef __APPLE__ + // Detect if we are being translated by Rosetta. OSPRay uses AVX instructions + // which are not supported. + { + int is_translated = 0; + size_t size = sizeof(is_translated); + if (sysctlbyname("sysctl.proc_translated", &is_translated, &size, nullptr, 0) == -1) + { + if (errno == ENOENT) + { + is_translated = 0; + } + else + { + // Error occurred. Just continue and let it work if it can or crash if + // it doesn't. + } + } + if (is_translated) + { + is_supported = false; + } + } +#endif + + ////////////////////////////////////////////////////////////////////////////// + // See the comment at the beginning of any conditions. + ////////////////////////////////////////////////////////////////////////////// + + detected = true; + return is_supported; +} + // ---------------------------------------------------------------------------- bool vtkOSPRayPass::IsBackendAvailable(const char* choice) { + if (!vtkOSPRayPass::IsSupported()) + { + return false; + } std::set bends = rtwGetAvailableBackends(); if (!strcmp(choice, "OSPRay raycaster")) { diff --git a/Rendering/RayTracing/vtkOSPRayPass.h b/Rendering/RayTracing/vtkOSPRayPass.h index a38bc7a5d..bf74b84cf 100644 --- a/Rendering/RayTracing/vtkOSPRayPass.h +++ b/Rendering/RayTracing/vtkOSPRayPass.h @@ -85,6 +85,11 @@ public: static void RTInit(); static void RTShutdown(); + /** + * A run time query to see if OSPRay can possibly work. + */ + static bool IsSupported(); + /** * A run time query to see if a particular backend is available. * Eg. "OSPRay raycaster", "OSPRay pathtracer" or "OptiX pathtracer". diff --git a/Rendering/RayTracing/vtkOSPRayWindowNode.cxx b/Rendering/RayTracing/vtkOSPRayWindowNode.cxx index 04dc29316..81eb24cda 100644 --- a/Rendering/RayTracing/vtkOSPRayWindowNode.cxx +++ b/Rendering/RayTracing/vtkOSPRayWindowNode.cxx @@ -54,6 +54,17 @@ void vtkOSPRayWindowNode::PrintSelf(ostream& os, vtkIndent indent) //---------------------------------------------------------------------------- void vtkOSPRayWindowNode::Render(bool prepass) { + if (!vtkOSPRayPass::IsSupported()) + { + static bool warned = false; + if (!warned) + { + vtkWarningMacro(<< "Ignoring render request because OSPRay is not supported."); + warned = true; + } + return; + } + if (!prepass) { // composite all renderers framebuffers together diff --git a/ThirdParty/hdf5/update.sh b/ThirdParty/hdf5/update.sh index b796b4655..b9b179fed 100755 --- a/ThirdParty/hdf5/update.sh +++ b/ThirdParty/hdf5/update.sh @@ -8,7 +8,7 @@ readonly name="hdf5" readonly ownership="HDF Upstream " readonly subtree="ThirdParty/$name/vtk$name" readonly repo="https://gitlab.kitware.com/third-party/hdf5.git" -readonly tag="for/vtk-20200417-1.10.6" +readonly tag="for/vtk-20210227-1.10.6" readonly paths=" CMakeFilters.cmake CMakeInstallation.cmake @@ -45,9 +45,9 @@ README.kitware.md extract_source () { git_archive pushd "$extractdir/$name-reduced" - find -name Makefile.am -delete - find -name Makefile.in -delete - find -name "*.lnt" -delete + find . -name Makefile.am -delete + find . -name Makefile.in -delete + find . -name "*.lnt" -delete rm -v src/.indent.pro popd } diff --git a/Utilities/DICOMParser/DICOMParser.cxx b/Utilities/DICOMParser/DICOMParser.cxx index b675b855a..74bc98ab7 100644 --- a/Utilities/DICOMParser/DICOMParser.cxx +++ b/Utilities/DICOMParser/DICOMParser.cxx @@ -522,13 +522,13 @@ void DICOMParser::InitTypeMap() doublebyte group; doublebyte element; - VRTypes datatype; + DICOMTypeValue datatype; for (int i = 0; i < num_tags; i++) { group = dicom_tags[i].group; element = dicom_tags[i].element; - datatype = static_cast(dicom_tags[i].datatype); + datatype = static_cast(dicom_tags[i].datatype); Implementation->TypeMap.insert( dicom_stl::pair(DICOMMapKey(group, element), datatype)); } diff --git a/Utilities/KWSys/vtksys/Base64.c b/Utilities/KWSys/vtksys/Base64.c index bf876f2d5..42650184a 100644 --- a/Utilities/KWSys/vtksys/Base64.c +++ b/Utilities/KWSys/vtksys/Base64.c @@ -130,7 +130,10 @@ size_t kwsysBase64_Encode(const unsigned char* input, size_t length, /* Decode 4 bytes into a 3 byte string. */ int kwsysBase64_Decode3(const unsigned char* src, unsigned char* dest) { - unsigned char d0, d1, d2, d3; + unsigned char d0; + unsigned char d1; + unsigned char d2; + unsigned char d3; d0 = kwsysBase64DecodeChar(src[0]); d1 = kwsysBase64DecodeChar(src[1]); diff --git a/Utilities/KWSys/vtksys/CMakeLists.txt b/Utilities/KWSys/vtksys/CMakeLists.txt index 5de2776dd..b0a854292 100644 --- a/Utilities/KWSys/vtksys/CMakeLists.txt +++ b/Utilities/KWSys/vtksys/CMakeLists.txt @@ -146,7 +146,6 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) set(KWSYS_USE_SystemTools 1) set(KWSYS_USE_CommandLineArguments 1) set(KWSYS_USE_Terminal 1) - set(KWSYS_USE_IOStream 1) set(KWSYS_USE_FStream 1) set(KWSYS_USE_String 1) set(KWSYS_USE_SystemInformation 1) @@ -360,67 +359,12 @@ endif() # capabilities and parent project's request. Enforce 0/1 as only # possible values for configuration into Configure.hxx. -# Check existence and uniqueness of long long and __int64. -KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_LONG_LONG - "Checking whether C++ compiler has 'long long'" DIRECT) -KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS___INT64 - "Checking whether C++ compiler has '__int64'" DIRECT) -if(KWSYS_CXX_HAS___INT64) - KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_AND___INT64 - "Checking whether long and __int64 are the same type" DIRECT) - if(KWSYS_CXX_HAS_LONG_LONG) - KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_LONG_AND___INT64 - "Checking whether long long and __int64 are the same type" DIRECT) - endif() -endif() - -# Enable the "long long" type if it is available. It is standard in -# C99 and C++03 but not in earlier standards. -if(KWSYS_CXX_HAS_LONG_LONG) - set(KWSYS_USE_LONG_LONG 1) -else() - set(KWSYS_USE_LONG_LONG 0) -endif() - -# Enable the "__int64" type if it is available and unique. It is not -# standard. -set(KWSYS_USE___INT64 0) -if(KWSYS_CXX_HAS___INT64) - if(NOT KWSYS_CXX_SAME_LONG_AND___INT64) - if(NOT KWSYS_CXX_SAME_LONG_LONG_AND___INT64) - set(KWSYS_USE___INT64 1) - endif() - endif() -endif() - if(KWSYS_USE_Encoding) # Look for type size helper macros. KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_WSTRING "Checking whether wstring is available" DIRECT) endif() -if(KWSYS_USE_IOStream) - # Determine whether iostreams support long long. - if(KWSYS_CXX_HAS_LONG_LONG) - KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM_LONG_LONG - "Checking if istream supports long long" DIRECT) - KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM_LONG_LONG - "Checking if ostream supports long long" DIRECT) - else() - set(KWSYS_IOS_HAS_ISTREAM_LONG_LONG 0) - set(KWSYS_IOS_HAS_OSTREAM_LONG_LONG 0) - endif() - if(KWSYS_CXX_HAS___INT64) - KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM___INT64 - "Checking if istream supports __int64" DIRECT) - KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM___INT64 - "Checking if ostream supports __int64" DIRECT) - else() - set(KWSYS_IOS_HAS_ISTREAM___INT64 0) - set(KWSYS_IOS_HAS_OSTREAM___INT64 0) - endif() -endif() - if(KWSYS_NAMESPACE MATCHES "^kwsys$") set(KWSYS_NAME_IS_KWSYS 1) else() @@ -569,24 +513,6 @@ if(KWSYS_USE_SystemInformation) set_property(SOURCE SystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_CXX_HAS_RLIMIT64=1) endif() - KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOL - "Checking whether CXX compiler has atol" DIRECT) - if(KWSYS_CXX_HAS_ATOL) - set_property(SOURCE SystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOL=1) - endif() - KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOLL - "Checking whether CXX compiler has atoll" DIRECT) - if(KWSYS_CXX_HAS_ATOLL) - set_property(SOURCE SystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOLL=1) - endif() - KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS__ATOI64 - "Checking whether CXX compiler has _atoi64" DIRECT) - if(KWSYS_CXX_HAS__ATOI64) - set_property(SOURCE SystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1) - endif() if(UNIX) include(CheckIncludeFileCXX) # check for simple stack trace @@ -650,36 +576,6 @@ if(KWSYS_USE_SystemInformation) endif() endif() endif() - if(BORLAND) - KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM - "Checking whether Borland CXX compiler supports assembler instructions" DIRECT) - if(KWSYS_CXX_HAS_BORLAND_ASM) - set_property(SOURCE SystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM=1) - KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM_CPUID - "Checking whether Borland CXX compiler supports CPUID assembler instruction" DIRECT) - if(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) - set_property(SOURCE SystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM_CPUID=1) - endif() - endif() - endif() - if(KWSYS_USE___INT64) - set_property(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_USE___INT64=1) - endif() - if(KWSYS_USE_LONG_LONG) - set_property(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_USE_LONG_LONG=1) - endif() - if(KWSYS_IOS_HAS_OSTREAM_LONG_LONG) - set_property(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM_LONG_LONG=1) - endif() - if(KWSYS_IOS_HAS_OSTREAM___INT64) - set_property(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY - COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM___INT64=1) - endif() if(KWSYS_BUILD_SHARED) set_property(SOURCE SystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_BUILD_SHARED=1) @@ -731,16 +627,10 @@ set(KWSYS_CLASSES) set(KWSYS_H_FILES Configure SharedForward) set(KWSYS_HXX_FILES Configure String) -if(NOT CMake_SOURCE_DIR) - set(KWSYS_HXX_FILES ${KWSYS_HXX_FILES} - hashtable hash_fun hash_map hash_set - ) -endif() - # Add selected C++ classes. set(cppclasses Directory DynamicLoader Encoding Glob RegularExpression SystemTools - CommandLineArguments IOStream FStream SystemInformation ConsoleBuf + CommandLineArguments FStream SystemInformation ConsoleBuf ) foreach(cpp ${cppclasses}) if(KWSYS_USE_${cpp}) @@ -1071,11 +961,6 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) endforeach() # C++ tests - if(NOT WATCOM AND NOT CMake_SOURCE_DIR) - set(KWSYS_CXX_TESTS - testHashSTL.cxx - ) - endif() set(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testConfigure.cxx testSystemTools.cxx @@ -1198,9 +1083,7 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) add_executable(${KWSYS_NAMESPACE}TestProcess testProcess.c) set_property(TARGET ${KWSYS_NAMESPACE}TestProcess PROPERTY LABELS ${KWSYS_LABELS_EXE}) target_link_libraries(${KWSYS_NAMESPACE}TestProcess ${KWSYS_TARGET_C_LINK}) - if(NOT CYGWIN) - set(KWSYS_TEST_PROCESS_7 7) - endif() + #set(KWSYS_TEST_PROCESS_7 7) # uncomment to run timing-sensitive test locally foreach(n 1 2 3 4 5 6 ${KWSYS_TEST_PROCESS_7} 9 10) add_test(kwsys.testProcess-${n} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestProcess ${n}) set_property(TEST kwsys.testProcess-${n} PROPERTY LABELS ${KWSYS_LABELS_TEST}) diff --git a/Utilities/KWSys/vtksys/CTestConfig.cmake b/Utilities/KWSys/vtksys/CTestConfig.cmake index 1339ffc2d..99d197ebc 100644 --- a/Utilities/KWSys/vtksys/CTestConfig.cmake +++ b/Utilities/KWSys/vtksys/CTestConfig.cmake @@ -3,7 +3,9 @@ set(CTEST_PROJECT_NAME "KWSys") set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT") -set(CTEST_DROP_METHOD "http") +if (NOT CTEST_DROP_METHOD STREQUAL "https") + set(CTEST_DROP_METHOD "http") +endif () set(CTEST_DROP_SITE "open.cdash.org") set(CTEST_DROP_LOCATION "/submit.php?project=KWSys") set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/Utilities/KWSys/vtksys/CommandLineArguments.cxx b/Utilities/KWSys/vtksys/CommandLineArguments.cxx index a2ed874c8..e45db36ac 100644 --- a/Utilities/KWSys/vtksys/CommandLineArguments.cxx +++ b/Utilities/KWSys/vtksys/CommandLineArguments.cxx @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include +#include +#include #ifdef _MSC_VER # pragma warning(disable : 4786) diff --git a/Utilities/KWSys/vtksys/Configure.h.in b/Utilities/KWSys/vtksys/Configure.h.in index 5323c57be..8a237cea3 100644 --- a/Utilities/KWSys/vtksys/Configure.h.in +++ b/Utilities/KWSys/vtksys/Configure.h.in @@ -13,9 +13,6 @@ /* Disable some warnings inside kwsys source files. */ #if defined(KWSYS_NAMESPACE) -# if defined(__BORLANDC__) -# pragma warn - 8027 /* function not inlined. */ -# endif # if defined(__INTEL_COMPILER) # pragma warning(disable : 1572) /* floating-point equality test */ # endif @@ -68,11 +65,6 @@ # pragma warning(disable : 4710) /* function not inlined */ # pragma warning(disable : 4786) /* identifier truncated in debug info */ # endif -# if defined(__BORLANDC__) && !defined(__cplusplus) -/* Code has no effect; raised by winnt.h in C (not C++) when ignoring an - unused parameter using "(param)" syntax (i.e. no cast to void). */ -# pragma warn - 8019 -# endif #endif /* MSVC 6.0 in release mode will warn about code it produces with its diff --git a/Utilities/KWSys/vtksys/Directory.cxx b/Utilities/KWSys/vtksys/Directory.cxx index d6409484c..0c2190aee 100644 --- a/Utilities/KWSys/vtksys/Directory.cxx +++ b/Utilities/KWSys/vtksys/Directory.cxx @@ -92,26 +92,12 @@ void Directory::Clear() # include # include -// Wide function names can vary depending on compiler: -# ifdef __BORLANDC__ -# define _wfindfirst_func __wfindfirst -# define _wfindnext_func __wfindnext -# else -# define _wfindfirst_func _wfindfirst -# define _wfindnext_func _wfindnext -# endif - namespace KWSYS_NAMESPACE { -bool Directory::Load(const std::string& name) +bool Directory::Load(const std::string& name, std::string* errorMessage) { this->Clear(); -# if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__) - // Older Visual C++ and Embarcadero compilers. - long srchHandle; -# else // Newer Visual C++ intptr_t srchHandle; -# endif char* buf; size_t n = name.size(); if (name.back() == '/' || name.back() == '\\') { @@ -130,8 +116,8 @@ bool Directory::Load(const std::string& name) struct _wfinddata_t data; // data of current file // Now put them into the file array - srchHandle = _wfindfirst_func( - (wchar_t*)Encoding::ToWindowsExtendedPath(buf).c_str(), &data); + srchHandle = + _wfindfirst((wchar_t*)Encoding::ToWindowsExtendedPath(buf).c_str(), &data); delete[] buf; if (srchHandle == -1) { @@ -141,19 +127,15 @@ bool Directory::Load(const std::string& name) // Loop through names do { this->Internal->Files.push_back(Encoding::ToNarrow(data.name)); - } while (_wfindnext_func(srchHandle, &data) != -1); + } while (_wfindnext(srchHandle, &data) != -1); this->Internal->Path = name; return _findclose(srchHandle) != -1; } -unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) +unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name, + std::string* errorMessage) { -# if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__) - // Older Visual C++ and Embarcadero compilers. - long srchHandle; -# else // Newer Visual C++ intptr_t srchHandle; -# endif char* buf; size_t n = name.size(); if (name.back() == '/') { @@ -166,8 +148,7 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) struct _wfinddata_t data; // data of current file // Now put them into the file array - srchHandle = - _wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data); + srchHandle = _wfindfirst((wchar_t*)Encoding::ToWide(buf).c_str(), &data); delete[] buf; if (srchHandle == -1) { @@ -178,7 +159,7 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) unsigned long count = 0; do { count++; - } while (_wfindnext_func(srchHandle, &data) != -1); + } while (_wfindnext(srchHandle, &data) != -1); _findclose(srchHandle); return count; } @@ -192,6 +173,8 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) # include # include +# include +# include // PGI with glibc has trouble with dirent and large file support: // http://www.pgroup.com/userforum/viewtopic.php? @@ -209,29 +192,46 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) namespace KWSYS_NAMESPACE { -bool Directory::Load(const std::string& name) +bool Directory::Load(const std::string& name, std::string* errorMessage) { this->Clear(); + errno = 0; DIR* dir = opendir(name.c_str()); if (!dir) { + if (errorMessage != nullptr) { + *errorMessage = std::string(strerror(errno)); + } return false; } + errno = 0; for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) { this->Internal->Files.emplace_back(d->d_name); } + if (errno != 0) { + if (errorMessage != nullptr) { + *errorMessage = std::string(strerror(errno)); + } + return false; + } + this->Internal->Path = name; closedir(dir); return true; } -unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) +unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name, + std::string* errorMessage) { + errno = 0; DIR* dir = opendir(name.c_str()); if (!dir) { + if (errorMessage != nullptr) { + *errorMessage = std::string(strerror(errno)); + } return 0; } @@ -239,6 +239,13 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) { count++; } + if (errno != 0) { + if (errorMessage != nullptr) { + *errorMessage = std::string(strerror(errno)); + } + return false; + } + closedir(dir); return count; } diff --git a/Utilities/KWSys/vtksys/Directory.hxx.in b/Utilities/KWSys/vtksys/Directory.hxx.in index 9b0f4c33c..7bc9db024 100644 --- a/Utilities/KWSys/vtksys/Directory.hxx.in +++ b/Utilities/KWSys/vtksys/Directory.hxx.in @@ -35,7 +35,7 @@ public: * in that directory. 0 is returned if the directory can not be * opened, 1 if it is opened. */ - bool Load(const std::string&); + bool Load(const std::string&, std::string* errorMessage = nullptr); /** * Return the number of files in the current directory. @@ -46,7 +46,8 @@ public: * Return the number of files in the specified directory. * A higher performance static method. */ - static unsigned long GetNumberOfFilesInDirectory(const std::string&); + static unsigned long GetNumberOfFilesInDirectory( + const std::string&, std::string* errorMessage = nullptr); /** * Return the file at the given index, the indexing is 0 based diff --git a/Utilities/KWSys/vtksys/DynamicLoader.cxx b/Utilities/KWSys/vtksys/DynamicLoader.cxx index a4b864118..66ee9eafa 100644 --- a/Utilities/KWSys/vtksys/DynamicLoader.cxx +++ b/Utilities/KWSys/vtksys/DynamicLoader.cxx @@ -246,17 +246,6 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress( // should have a tool to help get the symbol with the desired // calling convention. Currently we assume cdecl. // - // Borland: - // __cdecl = "_func" (default) - // __fastcall = "@_func" - // __stdcall = "func" - // - // Watcom: - // __cdecl = "_func" - // __fastcall = "@_func@X" - // __stdcall = "_func@X" - // __watcall = "func_" (default) - // // MSVC: // __cdecl = "func" (default) // __fastcall = "@_func@X" @@ -265,20 +254,9 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress( // Note that the "@X" part of the name above is the total size (in // bytes) of the arguments on the stack. void* result; -# if defined(__BORLANDC__) || defined(__WATCOMC__) - // Need to prepend symbols with '_' - std::string ssym = '_' + sym; - const char* rsym = ssym.c_str(); -# else const char* rsym = sym.c_str(); -# endif result = (void*)GetProcAddress(lib, rsym); -// Hack to cast pointer-to-data to pointer-to-function. -# ifdef __WATCOMC__ - return *(DynamicLoader::SymbolPointer*)(&result); -# else return *reinterpret_cast(&result); -# endif } # define DYNLOAD_ERROR_BUFFER_SIZE 1024 diff --git a/Utilities/KWSys/vtksys/EncodingCXX.cxx b/Utilities/KWSys/vtksys/EncodingCXX.cxx index 5cad934ec..c68c73c8e 100644 --- a/Utilities/KWSys/vtksys/EncodingCXX.cxx +++ b/Utilities/KWSys/vtksys/EncodingCXX.cxx @@ -17,8 +17,8 @@ # include "Encoding.hxx.in" #endif -#include -#include +#include +#include #include #ifdef _MSC_VER diff --git a/Utilities/KWSys/vtksys/FStream.hxx.in b/Utilities/KWSys/vtksys/FStream.hxx.in index b42448892..55a7fb195 100644 --- a/Utilities/KWSys/vtksys/FStream.hxx.in +++ b/Utilities/KWSys/vtksys/FStream.hxx.in @@ -166,6 +166,50 @@ protected: FILE* file_; }; +template > +class basic_fstream + : public std::basic_iostream + , public basic_efilebuf +{ +public: + typedef typename basic_efilebuf::internal_buffer_type + internal_buffer_type; + typedef std::basic_iostream internal_stream_type; + + basic_fstream() + : internal_stream_type(new internal_buffer_type()) + { + this->buf_ = + static_cast(internal_stream_type::rdbuf()); + } + explicit basic_fstream(char const* file_name, + std::ios_base::openmode mode = std::ios_base::in | + std::ios_base::out) + : internal_stream_type(new internal_buffer_type()) + { + this->buf_ = + static_cast(internal_stream_type::rdbuf()); + open(file_name, mode); + } + + void open(char const* file_name, + std::ios_base::openmode mode = std::ios_base::in | + std::ios_base::out) + { + this->_set_state(this->_open(file_name, mode), this, this); + } + + bool is_open() { return this->_is_open(); } + + void close() { this->_set_state(this->_close(), this, this); } + + using basic_efilebuf::_is_open; + + internal_buffer_type* rdbuf() const { return this->buf_; } + + ~basic_fstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT { close(); } +}; + template > class basic_ifstream : public std::basic_istream @@ -251,11 +295,13 @@ public: ~basic_ofstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT { close(); } }; +typedef basic_fstream fstream; typedef basic_ifstream ifstream; typedef basic_ofstream ofstream; # undef @KWSYS_NAMESPACE@_FStream_NOEXCEPT #else +using std::fstream; using std::ofstream; using std::ifstream; #endif diff --git a/Utilities/KWSys/vtksys/Glob.cxx b/Utilities/KWSys/vtksys/Glob.cxx index 8e30f92f2..c6d4b1985 100644 --- a/Utilities/KWSys/vtksys/Glob.cxx +++ b/Utilities/KWSys/vtksys/Glob.cxx @@ -23,11 +23,11 @@ #include #include -#include -#include -#include +#include +#include +#include namespace KWSYS_NAMESPACE { -#if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__APPLE__) // On Windows and Apple, no difference between lower and upper case # define KWSYS_GLOB_CASE_INDEPENDENT #endif @@ -182,7 +182,15 @@ bool Glob::RecurseDirectory(std::string::size_type start, const std::string& dir, GlobMessages* messages) { kwsys::Directory d; - if (!d.Load(dir)) { + std::string errorMessage; + if (!d.Load(dir, &errorMessage)) { + if (messages) { + if (!errorMessage.empty()) { + messages->push_back(Message(Glob::warning, + "Error listing directory '" + dir + + "'! Reason: '" + errorMessage + "'")); + } + } return true; } unsigned long cc; @@ -278,7 +286,9 @@ void Glob::ProcessDirectory(std::string::size_type start, // std::cout << "ProcessDirectory: " << dir << std::endl; bool last = (start == this->Internals->Expressions.size() - 1); if (last && this->Recurse) { - this->RecurseDirectory(start, dir, messages); + if (kwsys::SystemTools::FileIsDirectory(dir)) { + this->RecurseDirectory(start, dir, messages); + } return; } diff --git a/Utilities/KWSys/vtksys/Glob.hxx.in b/Utilities/KWSys/vtksys/Glob.hxx.in index 170766f4b..e8474e200 100644 --- a/Utilities/KWSys/vtksys/Glob.hxx.in +++ b/Utilities/KWSys/vtksys/Glob.hxx.in @@ -28,6 +28,7 @@ public: enum MessageType { error, + warning, cyclicRecursion }; @@ -125,8 +126,8 @@ protected: bool RecurseListDirs; private: - Glob(const Glob&); // Not implemented. - void operator=(const Glob&); // Not implemented. + Glob(const Glob&) = delete; + void operator=(const Glob&) = delete; }; } // namespace @KWSYS_NAMESPACE@ diff --git a/Utilities/KWSys/vtksys/IOStream.cxx b/Utilities/KWSys/vtksys/IOStream.cxx deleted file mode 100644 index e21f87d45..000000000 --- a/Utilities/KWSys/vtksys/IOStream.cxx +++ /dev/null @@ -1,255 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#include "kwsysPrivate.h" -#include KWSYS_HEADER(Configure.hxx) - -// Include the streams library. -#include -#include KWSYS_HEADER(IOStream.hxx) - -// Work-around CMake dependency scanning limitation. This must -// duplicate the above list of headers. -#if 0 -# include "Configure.hxx.in" -# include "IOStream.hxx.in" -#endif - -// Implement the rest of this file only if it is needed. -#if KWSYS_IOS_NEED_OPERATORS_LL - -# include // sscanf, sprintf -# include // memchr - -# if defined(_MAX_INT_DIG) -# define KWSYS_IOS_INT64_MAX_DIG _MAX_INT_DIG -# else -# define KWSYS_IOS_INT64_MAX_DIG 32 -# endif - -namespace KWSYS_NAMESPACE { - -// Scan an input stream for an integer value. -static int IOStreamScanStream(std::istream& is, char* buffer) -{ - // Prepare to write to buffer. - char* out = buffer; - char* end = buffer + KWSYS_IOS_INT64_MAX_DIG - 1; - - // Look for leading sign. - if (is.peek() == '+') { - *out++ = '+'; - is.ignore(); - } else if (is.peek() == '-') { - *out++ = '-'; - is.ignore(); - } - - // Determine the base. If not specified in the stream, try to - // detect it from the input. A leading 0x means hex, and a leading - // 0 alone means octal. - int base = 0; - int flags = is.flags() & std::ios_base::basefield; - if (flags == std::ios_base::oct) { - base = 8; - } else if (flags == std::ios_base::dec) { - base = 10; - } else if (flags == std::ios_base::hex) { - base = 16; - } - bool foundDigit = false; - bool foundNonZero = false; - if (is.peek() == '0') { - foundDigit = true; - is.ignore(); - if ((is.peek() == 'x' || is.peek() == 'X') && (base == 0 || base == 16)) { - base = 16; - foundDigit = false; - is.ignore(); - } else if (base == 0) { - base = 8; - } - } - - // Determine the range of digits allowed for this number. - const char* digits = "0123456789abcdefABCDEF"; - int maxDigitIndex = 10; - if (base == 8) { - maxDigitIndex = 8; - } else if (base == 16) { - maxDigitIndex = 10 + 6 + 6; - } - - // Scan until an invalid digit is found. - for (; is.peek() != EOF; is.ignore()) { - if (memchr(digits, *out = (char)is.peek(), maxDigitIndex) != 0) { - if ((foundNonZero || *out != '0') && out < end) { - ++out; - foundNonZero = true; - } - foundDigit = true; - } else { - break; - } - } - - // Correct the buffer contents for degenerate cases. - if (foundDigit && !foundNonZero) { - *out++ = '0'; - } else if (!foundDigit) { - out = buffer; - } - - // Terminate the string in the buffer. - *out = '\0'; - - return base; -} - -// Read an integer value from an input stream. -template -std::istream& IOStreamScanTemplate(std::istream& is, T& value, char type) -{ - int state = std::ios_base::goodbit; - - // Skip leading whitespace. - std::istream::sentry okay(is); - - if (okay) { - try { - // Copy the string to a buffer and construct the format string. - char buffer[KWSYS_IOS_INT64_MAX_DIG]; -# if defined(_MSC_VER) - char format[] = "%I64_"; - const int typeIndex = 4; -# else - char format[] = "%ll_"; - const int typeIndex = 3; -# endif - switch (IOStreamScanStream(is, buffer)) { - case 8: - format[typeIndex] = 'o'; - break; - case 0: // Default to decimal if not told otherwise. - case 10: - format[typeIndex] = type; - break; - case 16: - format[typeIndex] = 'x'; - break; - }; - - // Use sscanf to parse the number from the buffer. - T result; - int success = (sscanf(buffer, format, &result) == 1) ? 1 : 0; - - // Set flags for resulting state. - if (is.peek() == EOF) { - state |= std::ios_base::eofbit; - } - if (!success) { - state |= std::ios_base::failbit; - } else { - value = result; - } - } catch (...) { - state |= std::ios_base::badbit; - } - } - - is.setstate(std::ios_base::iostate(state)); - return is; -} - -// Print an integer value to an output stream. -template -std::ostream& IOStreamPrintTemplate(std::ostream& os, T value, char type) -{ - std::ostream::sentry okay(os); - if (okay) { - try { - // Construct the format string. - char format[8]; - char* f = format; - *f++ = '%'; - if (os.flags() & std::ios_base::showpos) { - *f++ = '+'; - } - if (os.flags() & std::ios_base::showbase) { - *f++ = '#'; - } -# if defined(_MSC_VER) - *f++ = 'I'; - *f++ = '6'; - *f++ = '4'; -# else - *f++ = 'l'; - *f++ = 'l'; -# endif - long bflags = os.flags() & std::ios_base::basefield; - if (bflags == std::ios_base::oct) { - *f++ = 'o'; - } else if (bflags != std::ios_base::hex) { - *f++ = type; - } else if (os.flags() & std::ios_base::uppercase) { - *f++ = 'X'; - } else { - *f++ = 'x'; - } - *f = '\0'; - - // Use sprintf to print to a buffer and then write the - // buffer to the stream. - char buffer[2 * KWSYS_IOS_INT64_MAX_DIG]; - sprintf(buffer, format, value); - os << buffer; - } catch (...) { - os.clear(os.rdstate() | std::ios_base::badbit); - } - } - return os; -} - -# if !KWSYS_IOS_HAS_ISTREAM_LONG_LONG -// Implement input stream operator for IOStreamSLL. -std::istream& IOStreamScan(std::istream& is, IOStreamSLL& value) -{ - return IOStreamScanTemplate(is, value, 'd'); -} - -// Implement input stream operator for IOStreamULL. -std::istream& IOStreamScan(std::istream& is, IOStreamULL& value) -{ - return IOStreamScanTemplate(is, value, 'u'); -} -# endif - -# if !KWSYS_IOS_HAS_OSTREAM_LONG_LONG -// Implement output stream operator for IOStreamSLL. -std::ostream& IOStreamPrint(std::ostream& os, IOStreamSLL value) -{ - return IOStreamPrintTemplate(os, value, 'd'); -} - -// Implement output stream operator for IOStreamULL. -std::ostream& IOStreamPrint(std::ostream& os, IOStreamULL value) -{ - return IOStreamPrintTemplate(os, value, 'u'); -} -# endif - -} // namespace KWSYS_NAMESPACE - -#else - -namespace KWSYS_NAMESPACE { - -// Create one public symbol in this object file to avoid warnings from -// archivers. -void IOStreamSymbolToAvoidWarning(); -void IOStreamSymbolToAvoidWarning() -{ -} - -} // namespace KWSYS_NAMESPACE - -#endif // KWSYS_IOS_NEED_OPERATORS_LL diff --git a/Utilities/KWSys/vtksys/IOStream.hxx.in b/Utilities/KWSys/vtksys/IOStream.hxx.in deleted file mode 100644 index db8a23ef5..000000000 --- a/Utilities/KWSys/vtksys/IOStream.hxx.in +++ /dev/null @@ -1,126 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#ifndef @KWSYS_NAMESPACE@_IOStream_hxx -#define @KWSYS_NAMESPACE@_IOStream_hxx - -#include - -/* Define these macros temporarily to keep the code readable. */ -#if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS -# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT -#endif - -/* Whether istream supports long long. */ -#define @KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG \ - @KWSYS_IOS_HAS_ISTREAM_LONG_LONG@ - -/* Whether ostream supports long long. */ -#define @KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG \ - @KWSYS_IOS_HAS_OSTREAM_LONG_LONG@ - -/* Determine whether we need to define the streaming operators for - long long or __int64. */ -#if @KWSYS_USE_LONG_LONG@ -# if !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG || \ - !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG -# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 1 -namespace @KWSYS_NAMESPACE@ { -typedef long long IOStreamSLL; -typedef unsigned long long IOStreamULL; -} -# endif -#elif defined(_MSC_VER) && _MSC_VER < 1300 -# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 1 -namespace @KWSYS_NAMESPACE@ { -typedef __int64 IOStreamSLL; -typedef unsigned __int64 IOStreamULL; -} -#endif -#if !defined(@KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL) -# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 0 -#endif - -#if @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL -# if !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG - -/* Input stream operator implementation functions. */ -namespace @KWSYS_NAMESPACE@ { -kwsysEXPORT std::istream& IOStreamScan(std::istream&, IOStreamSLL&); -kwsysEXPORT std::istream& IOStreamScan(std::istream&, IOStreamULL&); -} - -/* Provide input stream operator for long long. */ -# if !defined(@KWSYS_NAMESPACE@_IOS_NO_ISTREAM_LONG_LONG) && \ - !defined(KWSYS_IOS_ISTREAM_LONG_LONG_DEFINED) -# define KWSYS_IOS_ISTREAM_LONG_LONG_DEFINED -# define @KWSYS_NAMESPACE@_IOS_ISTREAM_LONG_LONG_DEFINED -inline std::istream& operator>>(std::istream& is, - @KWSYS_NAMESPACE@::IOStreamSLL& value) -{ - return @KWSYS_NAMESPACE@::IOStreamScan(is, value); -} -# endif - -/* Provide input stream operator for unsigned long long. */ -# if !defined(@KWSYS_NAMESPACE@_IOS_NO_ISTREAM_UNSIGNED_LONG_LONG) && \ - !defined(KWSYS_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED) -# define KWSYS_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED -# define @KWSYS_NAMESPACE@_IOS_ISTREAM_UNSIGNED_LONG_LONG_DEFINED -inline std::istream& operator>>(std::istream& is, - @KWSYS_NAMESPACE@::IOStreamULL& value) -{ - return @KWSYS_NAMESPACE@::IOStreamScan(is, value); -} -# endif -# endif /* !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG */ - -# if !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG - -/* Output stream operator implementation functions. */ -namespace @KWSYS_NAMESPACE@ { -kwsysEXPORT std::ostream& IOStreamPrint(std::ostream&, IOStreamSLL); -kwsysEXPORT std::ostream& IOStreamPrint(std::ostream&, IOStreamULL); -} - -/* Provide output stream operator for long long. */ -# if !defined(@KWSYS_NAMESPACE@_IOS_NO_OSTREAM_LONG_LONG) && \ - !defined(KWSYS_IOS_OSTREAM_LONG_LONG_DEFINED) -# define KWSYS_IOS_OSTREAM_LONG_LONG_DEFINED -# define @KWSYS_NAMESPACE@_IOS_OSTREAM_LONG_LONG_DEFINED -inline std::ostream& operator<<(std::ostream& os, - @KWSYS_NAMESPACE@::IOStreamSLL value) -{ - return @KWSYS_NAMESPACE@::IOStreamPrint(os, value); -} -# endif - -/* Provide output stream operator for unsigned long long. */ -# if !defined(@KWSYS_NAMESPACE@_IOS_NO_OSTREAM_UNSIGNED_LONG_LONG) && \ - !defined(KWSYS_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED) -# define KWSYS_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED -# define @KWSYS_NAMESPACE@_IOS_OSTREAM_UNSIGNED_LONG_LONG_DEFINED -inline std::ostream& operator<<(std::ostream& os, - @KWSYS_NAMESPACE@::IOStreamULL value) -{ - return @KWSYS_NAMESPACE@::IOStreamPrint(os, value); -} -# endif -# endif /* !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG */ -#endif /* @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL */ - -/* Undefine temporary macros. */ -#if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS -# undef kwsysEXPORT -#endif - -/* If building a C++ file in kwsys itself, give the source file - access to the macros without a configured namespace. */ -#if defined(KWSYS_NAMESPACE) -# define KWSYS_IOS_HAS_ISTREAM_LONG_LONG \ - @KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG -# define KWSYS_IOS_HAS_OSTREAM_LONG_LONG \ - @KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG -# define KWSYS_IOS_NEED_OPERATORS_LL @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL -#endif - -#endif diff --git a/Utilities/KWSys/vtksys/MD5.c b/Utilities/KWSys/vtksys/MD5.c index 97cf9ba68..fb18a5bba 100644 --- a/Utilities/KWSys/vtksys/MD5.c +++ b/Utilities/KWSys/vtksys/MD5.c @@ -171,8 +171,10 @@ typedef struct md5_state_s static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/) { - md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2], - d = pms->abcd[3]; + md5_word_t a = pms->abcd[0]; + md5_word_t b = pms->abcd[1]; + md5_word_t c = pms->abcd[2]; + md5_word_t d = pms->abcd[3]; md5_word_t t; #if BYTE_ORDER > 0 /* Define storage only for big-endian CPUs. */ @@ -227,9 +229,10 @@ static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/) # else # define xbuf X /* (static only) */ # endif - for (i = 0; i < 16; ++i, xp += 4) + for (i = 0; i < 16; ++i, xp += 4) { xbuf[i] = (md5_word_t)(xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24)); + } } #endif } @@ -367,34 +370,39 @@ static void md5_append(md5_state_t* pms, const md5_byte_t* data, size_t nbytes) size_t offset = (pms->count[0] >> 3) & 63; md5_word_t nbits = (md5_word_t)(nbytes << 3); - if (nbytes <= 0) + if (nbytes <= 0) { return; + } /* Update the message length. */ pms->count[1] += (md5_word_t)(nbytes >> 29); pms->count[0] += nbits; - if (pms->count[0] < nbits) + if (pms->count[0] < nbits) { pms->count[1]++; + } /* Process an initial partial block. */ if (offset) { size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes); memcpy(pms->buf + offset, p, copy); - if (offset + copy < 64) + if (offset + copy < 64) { return; + } p += copy; left -= copy; md5_process(pms, pms->buf); } /* Process full blocks. */ - for (; left >= 64; p += 64, left -= 64) + for (; left >= 64; p += 64, left -= 64) { md5_process(pms, p); + } /* Process a final partial block. */ - if (left) + if (left) { memcpy(pms->buf, p, left); + } } /* Finish the message and return the digest. */ @@ -409,14 +417,16 @@ static void md5_finish(md5_state_t* pms, md5_byte_t digest[16]) int i; /* Save the length before padding. */ - for (i = 0; i < 8; ++i) + for (i = 0; i < 8; ++i) { data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); + } /* Pad to 56 bytes mod 64. */ md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); /* Append the length. */ md5_append(pms, data, 8); - for (i = 0; i < 16; ++i) + for (i = 0; i < 16; ++i) { digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); + } } #if defined(__clang__) && !defined(__INTEL_COMPILER) diff --git a/Utilities/KWSys/vtksys/ProcessUNIX.c b/Utilities/KWSys/vtksys/ProcessUNIX.c index 5fde0b0a0..e1e7721b4 100644 --- a/Utilities/KWSys/vtksys/ProcessUNIX.c +++ b/Utilities/KWSys/vtksys/ProcessUNIX.c @@ -432,8 +432,8 @@ int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command) char const* const* c = command; kwsysProcess_ptrdiff_t n = 0; kwsysProcess_ptrdiff_t i = 0; - while (*c++) - ; + while (*c++) { + } n = c - command - 1; newCommands[cp->NumberOfCommands] = (char**)malloc((size_t)(n + 1) * sizeof(char*)); @@ -685,7 +685,8 @@ const char* kwsysProcess_GetErrorString(kwsysProcess* cp) { if (!cp) { return "Process management structure could not be allocated"; - } else if (cp->State == kwsysProcess_State_Error) { + } + if (cp->State == kwsysProcess_State_Error) { return cp->ErrorMessage; } return "Success"; @@ -695,7 +696,8 @@ const char* kwsysProcess_GetExceptionString(kwsysProcess* cp) { if (!(cp && cp->ProcessResults && (cp->NumberOfCommands > 0))) { return "GetExceptionString called with NULL process management structure"; - } else if (cp->State == kwsysProcess_State_Exception) { + } + if (cp->State == kwsysProcess_State_Exception) { return cp->ProcessResults[cp->NumberOfCommands - 1].ExitExceptionString; } return "No exception"; @@ -787,8 +789,8 @@ void kwsysProcess_Execute(kwsysProcess* cp) /* Some platforms specify that the chdir call may be interrupted. Repeat the call until it finishes. */ - while (((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR)) - ; + while (((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR)) { + } if (r < 0) { kwsysProcessCleanup(cp, 1); return; @@ -1014,8 +1016,8 @@ void kwsysProcess_Execute(kwsysProcess* cp) if (cp->RealWorkingDirectory) { /* Some platforms specify that the chdir call may be interrupted. Repeat the call until it finishes. */ - while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) - ; + while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) { + } free(cp->RealWorkingDirectory); cp->RealWorkingDirectory = 0; } @@ -1100,22 +1102,22 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length, if (wd.PipeId) { /* Data are ready on a pipe. */ return wd.PipeId; - } else if (wd.Expired) { + } + if (wd.Expired) { /* A timeout has expired. */ if (wd.User) { /* The user timeout has expired. It has no time left. */ return kwsysProcess_Pipe_Timeout; - } else { - /* The process timeout has expired. Kill the children now. */ - kwsysProcess_Kill(cp); - cp->Killed = 0; - cp->TimeoutExpired = 1; - return kwsysProcess_Pipe_None; } - } else { - /* No pipes are left open. */ + + /* The process timeout has expired. Kill the children now. */ + kwsysProcess_Kill(cp); + cp->Killed = 0; + cp->TimeoutExpired = 1; return kwsysProcess_Pipe_None; } + /* No pipes are left open. */ + return kwsysProcess_Pipe_None; } static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, @@ -1145,8 +1147,8 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, read until the operation is not interrupted. */ while (((n = read(cp->PipeReadEnds[i], cp->PipeBuffer, KWSYSPE_PIPE_BUFFER_SIZE)) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } if (n > 0) { /* We have data on this pipe. */ if (i == KWSYSPE_PIPE_SIGNAL) { @@ -1184,7 +1186,7 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, /* Make sure the set is empty (it should always be empty here anyway). */ - FD_ZERO(&cp->PipeSet); + FD_ZERO(&cp->PipeSet); // NOLINT(readability-isolate-declaration) /* Setup a timeout if required. */ if (wd->TimeoutTime.tv_sec < 0) { @@ -1219,15 +1221,16 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, /* Run select to block until data are available. Repeat call until it is not interrupted. */ while (((numReady = select(max + 1, &cp->PipeSet, 0, 0, timeout)) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } /* Check result of select. */ if (numReady == 0) { /* Select's timeout expired. */ wd->Expired = 1; return 1; - } else if (numReady < 0) { + } + if (numReady < 0) { /* Select returned an error. Leave the error description in the pipe buffer. */ strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE); @@ -1367,11 +1370,13 @@ int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout) cp->ProcessResults[prPipe].State = kwsysProcess_StateByIndex_Exited; cp->ProcessResults[prPipe].ExitException = kwsysProcess_Exception_None; cp->ProcessResults[prPipe].ExitValue = + // NOLINTNEXTLINE(google-readability-casting) (int)WEXITSTATUS(cp->ProcessResults[prPipe].ExitCode); } else if (WIFSIGNALED(cp->ProcessResults[prPipe].ExitCode)) { /* The child received an unhandled signal. */ cp->ProcessResults[prPipe].State = kwsysProcess_State_Exception; kwsysProcessSetExitExceptionByIndex( + // NOLINTNEXTLINE(google-readability-casting) cp, (int)WTERMSIG(cp->ProcessResults[prPipe].ExitCode), prPipe); } else { /* Error getting the child return code. */ @@ -1450,8 +1455,8 @@ void kwsysProcess_Kill(kwsysProcess* cp) /* Reap the child. Keep trying until the call is not interrupted. */ - while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && (errno == EINTR)) - ; + while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && (errno == EINTR)) { + } } } @@ -1502,7 +1507,7 @@ static int kwsysProcessInitialize(kwsysProcess* cp) cp->PipesLeft = 0; cp->CommandsLeft = 0; #if KWSYSPE_USE_SELECT - FD_ZERO(&cp->PipeSet); + FD_ZERO(&cp->PipeSet); // NOLINT(readability-isolate-declaration) #endif cp->State = kwsysProcess_State_Starting; cp->Killed = 0; @@ -1591,16 +1596,16 @@ static void kwsysProcessCleanup(kwsysProcess* cp, int error) /* Reap the child. Keep trying until the call is not interrupted. */ while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } } } } /* Restore the working directory. */ if (cp->RealWorkingDirectory) { - while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) - ; + while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) { + } } } @@ -1636,8 +1641,8 @@ static void kwsysProcessCleanupDescriptor(int* pfd) if (pfd && *pfd > 2) { /* Keep trying to close until it is not interrupted by a * signal. */ - while ((close(*pfd) < 0) && (errno == EINTR)) - ; + while ((close(*pfd) < 0) && (errno == EINTR)) { + } *pfd = -1; } } @@ -1662,8 +1667,8 @@ static void kwsysProcessClosePipes(kwsysProcess* cp) read until the operation is not interrupted. */ while ((read(cp->PipeReadEnds[i], cp->PipeBuffer, KWSYSPE_PIPE_BUFFER_SIZE) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } } #endif @@ -1690,7 +1695,8 @@ int decc$set_child_standard_streams(int fd1, int fd2, int fd3); static int kwsysProcessCreate(kwsysProcess* cp, int prIndex, kwsysProcessCreateInformation* si) { - sigset_t mask, old_mask; + sigset_t mask; + sigset_t old_mask; int pgidPipe[2]; char tmp; ssize_t readRes; @@ -1818,8 +1824,8 @@ static int kwsysProcessCreate(kwsysProcess* cp, int prIndex, /* Make sure the child is in the process group before we proceed. This avoids race conditions with calls to the kill function that we make for signalling process groups. */ - while ((readRes = read(pgidPipe[0], &tmp, 1)) > 0) - ; + while ((readRes = read(pgidPipe[0], &tmp, 1)) > 0) { + } if (readRes < 0) { sigprocmask(SIG_SETMASK, &old_mask, 0); kwsysProcessCleanupDescriptor(&si->ErrorPipe[0]); @@ -1847,8 +1853,8 @@ static int kwsysProcessCreate(kwsysProcess* cp, int prIndex, /* Keep trying to read until the operation is not interrupted. */ while (((n = read(si->ErrorPipe[0], cp->ErrorMessage + total, (size_t)(KWSYSPE_PIPE_BUFFER_SIZE - total))) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } if (n > 0) { total += n; } @@ -1873,7 +1879,8 @@ static void kwsysProcessDestroy(kwsysProcess* cp) int i; /* Temporarily disable signals that access ForkPIDs. We don't want them to read a reaped PID, and writes to ForkPIDs are not atomic. */ - sigset_t mask, old_mask; + sigset_t mask; + sigset_t old_mask; sigemptyset(&mask); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGTERM); @@ -1886,8 +1893,8 @@ static void kwsysProcessDestroy(kwsysProcess* cp) int result; while (((result = waitpid(cp->ForkPIDs[i], &cp->CommandExitCodes[i], WNOHANG)) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } if (result > 0) { /* This child has termianted. */ cp->ForkPIDs[i] = 0; @@ -2000,28 +2007,26 @@ static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime, if (timeoutTime->tv_sec < 0) { /* No timeout time has been requested. */ return 0; - } else { - /* Calculate the remaining time. */ - kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent(); - kwsysProcessTime timeLeft = - kwsysProcessTimeSubtract(*timeoutTime, currentTime); - if (timeLeft.tv_sec < 0 && userTimeout && *userTimeout <= 0) { - /* Caller has explicitly requested a zero timeout. */ - timeLeft.tv_sec = 0; - timeLeft.tv_usec = 0; - } + } + /* Calculate the remaining time. */ + kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent(); + kwsysProcessTime timeLeft = + kwsysProcessTimeSubtract(*timeoutTime, currentTime); + if (timeLeft.tv_sec < 0 && userTimeout && *userTimeout <= 0) { + /* Caller has explicitly requested a zero timeout. */ + timeLeft.tv_sec = 0; + timeLeft.tv_usec = 0; + } - if (timeLeft.tv_sec < 0 || - (timeLeft.tv_sec == 0 && timeLeft.tv_usec == 0 && zeroIsExpired)) { - /* Timeout has already expired. */ - return 1; - } else { - /* There is some time left. */ - timeoutLength->tv_sec = timeLeft.tv_sec; - timeoutLength->tv_usec = timeLeft.tv_usec; - return 0; - } + if (timeLeft.tv_sec < 0 || + (timeLeft.tv_sec == 0 && timeLeft.tv_usec == 0 && zeroIsExpired)) { + /* Timeout has already expired. */ + return 1; } + /* There is some time left. */ + timeoutLength->tv_sec = timeLeft.tv_sec; + timeoutLength->tv_usec = timeLeft.tv_usec; + return 0; } static kwsysProcessTime kwsysProcessTimeGetCurrent(void) @@ -2123,17 +2128,17 @@ static void kwsysProcessSetExitExceptionByIndex(kwsysProcess* cp, int sig, #endif #ifdef SIGABRT case SIGABRT: - KWSYSPE_CASE(Other, "Child aborted"); + KWSYSPE_CASE(Other, "Subprocess aborted"); break; #endif #ifdef SIGKILL case SIGKILL: - KWSYSPE_CASE(Other, "Child killed"); + KWSYSPE_CASE(Other, "Subprocess killed"); break; #endif #ifdef SIGTERM case SIGTERM: - KWSYSPE_CASE(Other, "Child terminated"); + KWSYSPE_CASE(Other, "Subprocess terminated"); break; #endif #ifdef SIGHUP @@ -2426,41 +2431,39 @@ static pid_t kwsysProcessFork(kwsysProcess* cp, if (middle_pid < 0) { /* Fork failed. Return as if we were not detaching. */ return middle_pid; - } else if (middle_pid == 0) { + } + if (middle_pid == 0) { /* This is the intermediate process. Create the real child. */ pid_t child_pid = fork(); if (child_pid == 0) { /* This is the real child process. There is nothing to do here. */ return 0; - } else { - /* Use the error pipe to report the pid to the real parent. */ - while ((write(si->ErrorPipe[1], &child_pid, sizeof(child_pid)) < 0) && - (errno == EINTR)) - ; - - /* Exit without cleanup. The parent holds all resources. */ - kwsysProcessExit(); - return 0; /* Never reached, but avoids SunCC warning. */ } - } else { - /* This is the original parent process. The intermediate - process will use the error pipe to report the pid of the - detached child. */ - pid_t child_pid; - int status; - while ((read(si->ErrorPipe[0], &child_pid, sizeof(child_pid)) < 0) && - (errno == EINTR)) - ; + /* Use the error pipe to report the pid to the real parent. */ + while ((write(si->ErrorPipe[1], &child_pid, sizeof(child_pid)) < 0) && + (errno == EINTR)) { + } - /* Wait for the intermediate process to exit and clean it up. */ - while ((waitpid(middle_pid, &status, 0) < 0) && (errno == EINTR)) - ; - return child_pid; + /* Exit without cleanup. The parent holds all resources. */ + kwsysProcessExit(); + return 0; /* Never reached, but avoids SunCC warning. */ } - } else { - /* Not creating a detached process. Use normal fork. */ - return fork(); + /* This is the original parent process. The intermediate + process will use the error pipe to report the pid of the + detached child. */ + pid_t child_pid; + int status; + while ((read(si->ErrorPipe[0], &child_pid, sizeof(child_pid)) < 0) && + (errno == EINTR)) { + } + + /* Wait for the intermediate process to exit and clean it up. */ + while ((waitpid(middle_pid, &status, 0) < 0) && (errno == EINTR)) { + } + return child_pid; } + /* Not creating a detached process. Use normal fork. */ + return fork(); } #endif @@ -2565,7 +2568,8 @@ static void kwsysProcessKill(pid_t process_id) /* Make sure the process started and provided a valid header. */ if (ps && fscanf(ps, "%*[^\n]\n") != EOF) { /* Look for processes whose parent is the process being killed. */ - int pid, ppid; + int pid; + int ppid; while (fscanf(ps, KWSYSPE_PS_FORMAT, &pid, &ppid) == 2) { if (ppid == process_id) { /* Recursively kill this child and its children. */ @@ -2727,8 +2731,8 @@ static int kwsysProcessesAdd(kwsysProcess* cp) sigemptyset(&newSigAction.sa_mask); while ((sigaction(SIGCHLD, &newSigAction, &kwsysProcessesOldSigChldAction) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } /* Install our handler for SIGINT / SIGTERM. Repeat call until it is not interrupted. */ @@ -2736,15 +2740,15 @@ static int kwsysProcessesAdd(kwsysProcess* cp) sigaddset(&newSigAction.sa_mask, SIGTERM); while ((sigaction(SIGINT, &newSigAction, &kwsysProcessesOldSigIntAction) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } sigemptyset(&newSigAction.sa_mask); sigaddset(&newSigAction.sa_mask, SIGINT); while ((sigaction(SIGTERM, &newSigAction, &kwsysProcessesOldSigIntAction) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } } } @@ -2775,14 +2779,14 @@ static void kwsysProcessesRemove(kwsysProcess* cp) /* Restore the signal handlers. Repeat call until it is not interrupted. */ while ((sigaction(SIGCHLD, &kwsysProcessesOldSigChldAction, 0) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } while ((sigaction(SIGINT, &kwsysProcessesOldSigIntAction, 0) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } while ((sigaction(SIGTERM, &kwsysProcessesOldSigTermAction, 0) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } /* Free the table of process pointers since it is now empty. This is safe because the signal handler has been removed. */ @@ -2808,7 +2812,10 @@ static void kwsysProcessesSignalHandler(int signum #endif ) { - int i, j, procStatus, old_errno = errno; + int i; + int j; + int procStatus; + int old_errno = errno; #if KWSYSPE_USE_SIGINFO (void)info; (void)ucontext; @@ -2865,8 +2872,8 @@ static void kwsysProcessesSignalHandler(int signum memset(&defSigAction, 0, sizeof(defSigAction)); defSigAction.sa_handler = SIG_DFL; sigemptyset(&defSigAction.sa_mask); - while ((sigaction(signum, &defSigAction, 0) < 0) && (errno == EINTR)) - ; + while ((sigaction(signum, &defSigAction, 0) < 0) && (errno == EINTR)) { + } /* Unmask the signal. */ sigemptyset(&unblockSet); sigaddset(&unblockSet, signum); diff --git a/Utilities/KWSys/vtksys/ProcessWin32.c b/Utilities/KWSys/vtksys/ProcessWin32.c index 56bbd2006..8f01684a1 100644 --- a/Utilities/KWSys/vtksys/ProcessWin32.c +++ b/Utilities/KWSys/vtksys/ProcessWin32.c @@ -31,9 +31,6 @@ a UNIX-style select system call. #include /* _unlink */ #include /* sprintf */ #include /* strlen, strdup */ -#ifdef __WATCOMC__ -# define _unlink unlink -#endif #ifndef _MAX_FNAME # define _MAX_FNAME 4096 @@ -48,11 +45,6 @@ a UNIX-style select system call. # pragma warning(disable : 4706) #endif -#if defined(__BORLANDC__) -# pragma warn - 8004 /* assigned a value that is never used */ -# pragma warn - 8060 /* Assignment inside if() condition. */ -#endif - /* There are pipes for the process pipeline's stdout and stderr. */ #define KWSYSPE_PIPE_COUNT 2 #define KWSYSPE_PIPE_STDOUT 0 @@ -970,7 +962,10 @@ void kwsysProcess_Execute(kwsysProcess* cp) kwsysProcessCleanup(cp, GetLastError()); return; } - SetCurrentDirectoryW(cp->WorkingDirectory); + if (!SetCurrentDirectoryW(cp->WorkingDirectory)) { + kwsysProcessCleanup(cp, GetLastError()); + return; + } } /* Setup the stdin pipe for the first process. */ diff --git a/Utilities/KWSys/vtksys/RegularExpression.cxx b/Utilities/KWSys/vtksys/RegularExpression.cxx index 5e6f8da50..fb4e38029 100644 --- a/Utilities/KWSys/vtksys/RegularExpression.cxx +++ b/Utilities/KWSys/vtksys/RegularExpression.cxx @@ -28,8 +28,8 @@ # include "RegularExpression.hxx.in" #endif -#include -#include +#include +#include namespace KWSYS_NAMESPACE { @@ -359,7 +359,7 @@ bool RegularExpression::compile(const char* exp) this->regmatch.clear(); // Small enough for pointer-storage convention? - if (comp.regsize >= 32767L) { // Probably could be 65535L. + if (comp.regsize >= 65535L) { // RAISE Error, SYM(RegularExpression), SYM(Expr_Too_Big), printf("RegularExpression::compile(): Expression too big.\n"); return false; @@ -367,8 +367,7 @@ bool RegularExpression::compile(const char* exp) // Allocate space. //#ifndef _WIN32 - if (this->program != nullptr) - delete[] this->program; + delete[] this->program; //#endif this->program = new char[comp.regsize]; this->progsize = static_cast(comp.regsize); diff --git a/Utilities/KWSys/vtksys/RegularExpression.hxx.in b/Utilities/KWSys/vtksys/RegularExpression.hxx.in index d11db8828..2709cde5f 100644 --- a/Utilities/KWSys/vtksys/RegularExpression.hxx.in +++ b/Utilities/KWSys/vtksys/RegularExpression.hxx.in @@ -26,12 +26,6 @@ #include -/* Disable useless Borland warnings. KWSys tries not to force things - on its includers, but there is no choice here. */ -#if defined(__BORLANDC__) -# pragma warn - 8027 /* function not inlined. */ -#endif - namespace @KWSYS_NAMESPACE@ { // Forward declaration diff --git a/Utilities/KWSys/vtksys/SharedForward.h.in b/Utilities/KWSys/vtksys/SharedForward.h.in index 5716cd4f1..091334b75 100644 --- a/Utilities/KWSys/vtksys/SharedForward.h.in +++ b/Utilities/KWSys/vtksys/SharedForward.h.in @@ -66,12 +66,6 @@ # endif # endif -# if defined(__BORLANDC__) && !defined(__cplusplus) -/* Code has no effect; raised by winnt.h in C (not C++) when ignoring an - unused parameter using "(param)" syntax (i.e. no cast to void). */ -# pragma warn - 8019 -# endif - /* Full path to the directory in which this executable is built. Do not include a trailing slash. */ # if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD) diff --git a/Utilities/KWSys/vtksys/String.hxx.in b/Utilities/KWSys/vtksys/String.hxx.in index db1cf22a9..c36f4ce4a 100644 --- a/Utilities/KWSys/vtksys/String.hxx.in +++ b/Utilities/KWSys/vtksys/String.hxx.in @@ -52,14 +52,6 @@ public: } }; // End Class: String -#if defined(__WATCOMC__) -inline bool operator<(String const& l, String const& r) -{ - return (static_cast(l) < - static_cast(r)); -} -#endif - } // namespace @KWSYS_NAMESPACE@ #endif diff --git a/Utilities/KWSys/vtksys/SystemInformation.cxx b/Utilities/KWSys/vtksys/SystemInformation.cxx index 95b06e189..7743eabe9 100644 --- a/Utilities/KWSys/vtksys/SystemInformation.cxx +++ b/Utilities/KWSys/vtksys/SystemInformation.cxx @@ -64,9 +64,9 @@ typedef int siginfo_t; #else # include -# include // extern int errno; +# include // extern int errno; +# include # include -# include # include // getrlimit # include # include // int uname(struct utsname *buf); @@ -163,39 +163,11 @@ typedef struct rlimit ResourceLimitType; # undef KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP #endif -#include // int isdigit(int c); +#include // int isdigit(int c); +#include +#include +#include #include -#include -#include -#include - -#if defined(KWSYS_USE_LONG_LONG) -# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG) -# define iostreamLongLong(x) (x) -# else -# define iostreamLongLong(x) ((long)(x)) -# endif -#elif defined(KWSYS_USE___INT64) -# if defined(KWSYS_IOS_HAS_OSTREAM___INT64) -# define iostreamLongLong(x) (x) -# else -# define iostreamLongLong(x) ((long)(x)) -# endif -#else -# error "No Long Long" -#endif - -#if defined(KWSYS_CXX_HAS_ATOLL) -# define atoLongLong atoll -#else -# if defined(KWSYS_CXX_HAS__ATOI64) -# define atoLongLong _atoi64 -# elif defined(KWSYS_CXX_HAS_ATOL) -# define atoLongLong atol -# else -# define atoLongLong atoi -# endif -#endif #if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(_WIN64) && \ !defined(__clang__) @@ -204,15 +176,15 @@ typedef struct rlimit ResourceLimitType; # define USE_ASM_INSTRUCTIONS 0 #endif -#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__clang__) +#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__clang__) && \ + !defined(_M_ARM64) # include # define USE_CPUID_INTRINSICS 1 #else # define USE_CPUID_INTRINSICS 0 #endif -#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || \ - defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) +#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS # define USE_CPUID 1 #else # define USE_CPUID 0 @@ -272,21 +244,6 @@ static bool call_cpuid(int select, int result[4]) } memcpy(result, tmp, sizeof(tmp)); -# elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) - unsigned int a, b, c, d; - __asm { - mov EAX, select; - cpuid - mov a, EAX; - mov b, EBX; - mov c, ECX; - mov d, EDX; - } - - result[0] = a; - result[1] = b; - result[2] = c; - result[3] = d; # endif // The cpuid instruction succeeded. @@ -312,7 +269,6 @@ using DELAY_FUNC = void (*)(unsigned int); class SystemInformationImplementation { public: - using LongLong = SystemInformation::LongLong; SystemInformationImplementation(); ~SystemInformationImplementation() = default; @@ -352,16 +308,16 @@ public: size_t GetTotalPhysicalMemory() const; size_t GetAvailablePhysicalMemory() const; - LongLong GetProcessId(); + long long GetProcessId(); // Retrieve memory information in KiB. - LongLong GetHostMemoryTotal(); - LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName); - LongLong GetHostMemoryUsed(); + long long GetHostMemoryTotal(); + long long GetHostMemoryAvailable(const char* hostLimitEnvVarName); + long long GetHostMemoryUsed(); - LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName, - const char* procLimitEnvVarName); - LongLong GetProcMemoryUsed(); + long long GetProcMemoryAvailable(const char* hostLimitEnvVarName, + const char* procLimitEnvVarName); + long long GetProcMemoryUsed(); double GetLoadAverage(); @@ -491,6 +447,8 @@ public: Motorola, HP, Hygon, + Zhaoxin, + Apple, UnknownManufacturer }; @@ -520,7 +478,8 @@ protected: void CPUCountWindows(); // For windows unsigned char GetAPICId(); // For windows bool IsSMTSupported() const; - static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For windows + static long long GetCyclesDifference(DELAY_FUNC, + unsigned int); // For windows // For Linux and Cygwin, /proc/cpuinfo formats are slightly different bool RetreiveInformationFromCpuInfoFile(); @@ -811,42 +770,41 @@ std::string SystemInformation::GetMemoryDescription( const char* hostLimitEnvVarName, const char* procLimitEnvVarName) { std::ostringstream oss; - oss << "Host Total: " << iostreamLongLong(this->GetHostMemoryTotal()) + oss << "Host Total: " << this->GetHostMemoryTotal() << " KiB, Host Available: " - << iostreamLongLong(this->GetHostMemoryAvailable(hostLimitEnvVarName)) + << this->GetHostMemoryAvailable(hostLimitEnvVarName) << " KiB, Process Available: " - << iostreamLongLong(this->GetProcMemoryAvailable(hostLimitEnvVarName, - procLimitEnvVarName)) + << this->GetProcMemoryAvailable(hostLimitEnvVarName, procLimitEnvVarName) << " KiB"; return oss.str(); } // host memory info in units of KiB. -SystemInformation::LongLong SystemInformation::GetHostMemoryTotal() +long long SystemInformation::GetHostMemoryTotal() { return this->Implementation->GetHostMemoryTotal(); } -SystemInformation::LongLong SystemInformation::GetHostMemoryAvailable( +long long SystemInformation::GetHostMemoryAvailable( const char* hostLimitEnvVarName) { return this->Implementation->GetHostMemoryAvailable(hostLimitEnvVarName); } -SystemInformation::LongLong SystemInformation::GetHostMemoryUsed() +long long SystemInformation::GetHostMemoryUsed() { return this->Implementation->GetHostMemoryUsed(); } // process memory info in units of KiB. -SystemInformation::LongLong SystemInformation::GetProcMemoryAvailable( +long long SystemInformation::GetProcMemoryAvailable( const char* hostLimitEnvVarName, const char* procLimitEnvVarName) { return this->Implementation->GetProcMemoryAvailable(hostLimitEnvVarName, procLimitEnvVarName); } -SystemInformation::LongLong SystemInformation::GetProcMemoryUsed() +long long SystemInformation::GetProcMemoryUsed() { return this->Implementation->GetProcMemoryUsed(); } @@ -856,7 +814,7 @@ double SystemInformation::GetLoadAverage() return this->Implementation->GetLoadAverage(); } -SystemInformation::LongLong SystemInformation::GetProcessId() +long long SystemInformation::GetProcessId() { return this->Implementation->GetProcessId(); } @@ -907,7 +865,7 @@ void SystemInformation::RunMemoryCheck() // Hide implementation details in an anonymous namespace. namespace { // ***************************************************************************** -#if defined(__linux) || defined(__APPLE__) +#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__) int LoadLines(FILE* file, std::vector& lines) { // Load each line in the given file into a the vector. @@ -937,7 +895,7 @@ int LoadLines(FILE* file, std::vector& lines) return nRead; } -# if defined(__linux) +# if defined(__linux) || defined(__CYGWIN__) // ***************************************************************************** int LoadLines(const char* fileName, std::vector& lines) { @@ -970,7 +928,7 @@ int NameValue(std::vector const& lines, std::string const& name, } #endif -#if defined(__linux) +#if defined(__linux) || defined(__CYGWIN__) // **************************************************************************** template int GetFieldsFromFile(const char* fileName, const char** fieldNames, T* values) @@ -1365,7 +1323,7 @@ std::string SymbolProperties::GetFileName(const std::string& path) const { std::string file(path); if (!this->ReportPath) { - size_t at = file.rfind("/"); + size_t at = file.rfind('/'); if (at != std::string::npos) { file.erase(0, at + 1); } @@ -1775,7 +1733,8 @@ const char* SystemInformationImplementation::GetVendorID() case NexGen: return "NexGen Inc., Advanced Micro Devices"; case IDT: - return "IDT\\Centaur, Via Inc."; + return "IDT\\Centaur, Via Inc., Shanghai Zhaoxin Semiconductor Co., " + "Ltd."; case UMC: return "United Microelectronics Corp."; case Rise: @@ -1792,6 +1751,10 @@ const char* SystemInformationImplementation::GetVendorID() return "Hewlett-Packard"; case Hygon: return "Chengdu Haiguang IC Design Co., Ltd."; + case Zhaoxin: + return "Shanghai Zhaoxin Semiconductor Co., Ltd."; + case Apple: + return "Apple"; case UnknownManufacturer: default: return "Unknown Manufacturer"; @@ -2153,7 +2116,10 @@ void SystemInformationImplementation::FindManufacturer( else if (this->ChipID.Vendor == "NexGenDriven") this->ChipManufacturer = NexGen; // NexGen Inc. (now AMD) else if (this->ChipID.Vendor == "CentaurHauls") - this->ChipManufacturer = IDT; // IDT/Centaur (now VIA) + this->ChipManufacturer = IDT; // original IDT/Centaur/VIA (now Zhaoxin) + else if (this->ChipID.Vendor == " Shanghai ") + this->ChipManufacturer = + Zhaoxin; // Shanghai Zhaoxin Semiconductor Co., Ltd. else if (this->ChipID.Vendor == "RiseRiseRise") this->ChipManufacturer = Rise; // Rise else if (this->ChipID.Vendor == "GenuineTMx86") @@ -2172,6 +2138,8 @@ void SystemInformationImplementation::FindManufacturer( this->ChipManufacturer = Motorola; // Motorola Microelectronics else if (family.compare(0, 7, "PA-RISC") == 0) this->ChipManufacturer = HP; // Hewlett-Packard + else if (this->ChipID.Vendor == "Apple") + this->ChipManufacturer = Apple; // Apple else this->ChipManufacturer = UnknownManufacturer; // Unknown manufacturer } @@ -3267,7 +3235,8 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() this->ChipID.ProcessorName = "C3"; break; default: - this->ChipID.ProcessorName = "Unknown IDT\\Centaur family"; + this->ChipID.ProcessorName = + "Unknown IDT\\Centaur\\VIA\\Zhaoxin family"; return false; } break; @@ -3276,13 +3245,63 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() case 6: this->ChipID.ProcessorName = "VIA Cyrix III - Samuel"; break; + case 0xf: + this->ChipID.ProcessorName = "Zhaoxin zxc"; + break; + default: + this->ChipID.ProcessorName = + "Unknown IDT\\Centaur\\VIA\\Zhaoxin family"; + return false; + } + break; + case 7: + switch (this->ChipID.Model) { + case 0x1b: + this->ChipID.ProcessorName = "Zhaoxin kx5000"; + break; + case 0x3b: + this->ChipID.ProcessorName = "Zhaoxin kx6000"; + break; + default: + this->ChipID.ProcessorName = + "Unknown IDT\\Centaur\\VIA\\Zhaoxin family"; + return false; + } + break; + default: + this->ChipID.ProcessorName = + "Unknown IDT\\Centaur\\VIA\\Zhaoxin family"; + return false; + } + break; + + case Zhaoxin: + switch (this->ChipID.Family) { + case 6: + switch (this->ChipID.Model) { + case 0x19: + this->ChipID.ProcessorName = "Zhaoxin zxc"; + break; + default: + this->ChipID.ProcessorName = "Unknown Zhaoxin family"; + return false; + } + break; + case 7: + switch (this->ChipID.Model) { + case 0x1b: + this->ChipID.ProcessorName = "Zhaoxin kx5000"; + break; + case 0x3b: + this->ChipID.ProcessorName = "Zhaoxin kx6000"; + break; default: - this->ChipID.ProcessorName = "Unknown IDT\\Centaur family"; + this->ChipID.ProcessorName = "Unknown Zhaoxin family"; return false; } break; default: - this->ChipID.ProcessorName = "Unknown IDT\\Centaur family"; + this->ChipID.ProcessorName = "Unknown Zhaoxin family"; return false; } break; @@ -3386,8 +3405,8 @@ std::string SystemInformationImplementation::ExtractValueFromCpuInfoFile( size_t pos = buffer.find(word, init); if (pos != std::string::npos) { this->CurrentPositionInFile = pos; - pos = buffer.find(":", pos); - size_t pos2 = buffer.find("\n", pos); + pos = buffer.find(':', pos); + size_t pos2 = buffer.find('\n', pos); if (pos != std::string::npos && pos2 != std::string::npos) { // It may happen that the beginning matches, but this is still not the // requested key. @@ -3437,7 +3456,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() pos = buffer.find("processor\t", pos + 1); } -#ifdef __linux +#if defined(__linux) || defined(__CYGWIN__) // Count sockets. std::set PhysicalIDs; std::string idc = this->ExtractValueFromCpuInfoFile(buffer, "physical id"); @@ -3458,8 +3477,8 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() this->NumberOfPhysicalCPU = NumberOfCoresPerSocket * (unsigned int)NumberOfSockets; -#else // __CYGWIN__ - // does not have "physical id" entries, neither "cpu cores" +#else + // For systems which do not have "physical id" entries, neither "cpu cores" // this has to be fixed for hyper-threading. std::string cpucount = this->ExtractValueFromCpuInfoFile(buffer, "cpu count"); @@ -3627,8 +3646,7 @@ bool SystemInformationImplementation::QueryProcessor() /** Get total system RAM in units of KiB. */ -SystemInformation::LongLong -SystemInformationImplementation::GetHostMemoryTotal() +long long SystemInformationImplementation::GetHostMemoryTotal() { #if defined(_WIN32) # if defined(_MSC_VER) && _MSC_VER < 1300 @@ -3642,8 +3660,8 @@ SystemInformationImplementation::GetHostMemoryTotal() GlobalMemoryStatusEx(&statex); return statex.ullTotalPhys / 1024; # endif -#elif defined(__linux) - SystemInformation::LongLong memTotal = 0; +#elif defined(__linux) || defined(__CYGWIN__) + long long memTotal = 0; int ierr = GetFieldFromFile("/proc/meminfo", "MemTotal:", memTotal); if (ierr) { return -1; @@ -3666,11 +3684,10 @@ SystemInformationImplementation::GetHostMemoryTotal() Get total system RAM in units of KiB. This may differ from the host total if a host-wide resource limit is applied. */ -SystemInformation::LongLong -SystemInformationImplementation::GetHostMemoryAvailable( +long long SystemInformationImplementation::GetHostMemoryAvailable( const char* hostLimitEnvVarName) { - SystemInformation::LongLong memTotal = this->GetHostMemoryTotal(); + long long memTotal = this->GetHostMemoryTotal(); // the following mechanism is provided for systems that // apply resource limits across groups of processes. @@ -3681,8 +3698,7 @@ SystemInformationImplementation::GetHostMemoryAvailable( if (hostLimitEnvVarName) { const char* hostLimitEnvVarValue = getenv(hostLimitEnvVarName); if (hostLimitEnvVarValue) { - SystemInformation::LongLong hostLimit = - atoLongLong(hostLimitEnvVarValue); + long long hostLimit = std::atoll(hostLimitEnvVarValue); if (hostLimit > 0) { memTotal = min(hostLimit, memTotal); } @@ -3696,20 +3712,17 @@ SystemInformationImplementation::GetHostMemoryAvailable( Get total system RAM in units of KiB. This may differ from the host total if a per-process resource limit is applied. */ -SystemInformation::LongLong -SystemInformationImplementation::GetProcMemoryAvailable( +long long SystemInformationImplementation::GetProcMemoryAvailable( const char* hostLimitEnvVarName, const char* procLimitEnvVarName) { - SystemInformation::LongLong memAvail = - this->GetHostMemoryAvailable(hostLimitEnvVarName); + long long memAvail = this->GetHostMemoryAvailable(hostLimitEnvVarName); // the following mechanism is provide for systems where rlimits // are not employed. Units are in KiB. if (procLimitEnvVarName) { const char* procLimitEnvVarValue = getenv(procLimitEnvVarName); if (procLimitEnvVarValue) { - SystemInformation::LongLong procLimit = - atoLongLong(procLimitEnvVarValue); + long long procLimit = std::atoll(procLimitEnvVarValue); if (procLimit > 0) { memAvail = min(procLimit, memAvail); } @@ -3721,28 +3734,24 @@ SystemInformationImplementation::GetProcMemoryAvailable( ResourceLimitType rlim; ierr = GetResourceLimit(RLIMIT_DATA, &rlim); if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) { - memAvail = - min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail); + memAvail = min((long long)rlim.rlim_cur / 1024, memAvail); } ierr = GetResourceLimit(RLIMIT_AS, &rlim); if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) { - memAvail = - min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail); + memAvail = min((long long)rlim.rlim_cur / 1024, memAvail); } #elif defined(__APPLE__) struct rlimit rlim; int ierr; ierr = getrlimit(RLIMIT_DATA, &rlim); if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) { - memAvail = - min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail); + memAvail = min((long long)rlim.rlim_cur / 1024, memAvail); } ierr = getrlimit(RLIMIT_RSS, &rlim); if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) { - memAvail = - min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail); + memAvail = min((long long)rlim.rlim_cur / 1024, memAvail); } #endif @@ -3752,8 +3761,7 @@ SystemInformationImplementation::GetProcMemoryAvailable( /** Get RAM used by all processes in the host, in units of KiB. */ -SystemInformation::LongLong -SystemInformationImplementation::GetHostMemoryUsed() +long long SystemInformationImplementation::GetHostMemoryUsed() { #if defined(_WIN32) # if defined(_MSC_VER) && _MSC_VER < 1300 @@ -3767,42 +3775,51 @@ SystemInformationImplementation::GetHostMemoryUsed() GlobalMemoryStatusEx(&statex); return (statex.ullTotalPhys - statex.ullAvailPhys) / 1024; # endif +#elif defined(__CYGWIN__) + const char* names[3] = { "MemTotal:", "MemFree:", nullptr }; + long long values[2] = { 0 }; + int ierr = GetFieldsFromFile("/proc/meminfo", names, values); + if (ierr) { + return ierr; + } + long long& memTotal = values[0]; + long long& memFree = values[1]; + return memTotal - memFree; #elif defined(__linux) // First try to use MemAvailable, but it only works on newer kernels const char* names2[3] = { "MemTotal:", "MemAvailable:", nullptr }; - SystemInformation::LongLong values2[2] = { SystemInformation::LongLong(0) }; + long long values2[2] = { 0 }; int ierr = GetFieldsFromFile("/proc/meminfo", names2, values2); if (ierr) { const char* names4[5] = { "MemTotal:", "MemFree:", "Buffers:", "Cached:", nullptr }; - SystemInformation::LongLong values4[4] = { SystemInformation::LongLong( - 0) }; + long long values4[4] = { 0 }; ierr = GetFieldsFromFile("/proc/meminfo", names4, values4); if (ierr) { return ierr; } - SystemInformation::LongLong& memTotal = values4[0]; - SystemInformation::LongLong& memFree = values4[1]; - SystemInformation::LongLong& memBuffers = values4[2]; - SystemInformation::LongLong& memCached = values4[3]; + long long& memTotal = values4[0]; + long long& memFree = values4[1]; + long long& memBuffers = values4[2]; + long long& memCached = values4[3]; return memTotal - memFree - memBuffers - memCached; } - SystemInformation::LongLong& memTotal = values2[0]; - SystemInformation::LongLong& memAvail = values2[1]; + long long& memTotal = values2[0]; + long long& memAvail = values2[1]; return memTotal - memAvail; #elif defined(__APPLE__) - SystemInformation::LongLong psz = getpagesize(); + long long psz = getpagesize(); if (psz < 1) { return -1; } const char* names[3] = { "Pages wired down:", "Pages active:", nullptr }; - SystemInformation::LongLong values[2] = { SystemInformation::LongLong(0) }; + long long values[2] = { 0 }; int ierr = GetFieldsFromCommand("vm_stat", names, values); if (ierr) { return -1; } - SystemInformation::LongLong& vmWired = values[0]; - SystemInformation::LongLong& vmActive = values[1]; + long long& vmWired = values[0]; + long long& vmActive = values[1]; return ((vmActive + vmWired) * psz) / 1024; #else return 0; @@ -3813,8 +3830,7 @@ SystemInformationImplementation::GetHostMemoryUsed() Get system RAM used by the process associated with the given process id in units of KiB. */ -SystemInformation::LongLong -SystemInformationImplementation::GetProcMemoryUsed() +long long SystemInformationImplementation::GetProcMemoryUsed() { #if defined(_WIN32) && defined(KWSYS_SYS_HAS_PSAPI) long pid = GetCurrentProcessId(); @@ -3830,15 +3846,15 @@ SystemInformationImplementation::GetProcMemoryUsed() return -2; } return pmc.WorkingSetSize / 1024; -#elif defined(__linux) - SystemInformation::LongLong memUsed = 0; +#elif defined(__linux) || defined(__CYGWIN__) + long long memUsed = 0; int ierr = GetFieldFromFile("/proc/self/status", "VmRSS:", memUsed); if (ierr) { return -1; } return memUsed; #elif defined(__APPLE__) - SystemInformation::LongLong memUsed = 0; + long long memUsed = 0; pid_t pid = getpid(); std::ostringstream oss; oss << "ps -o rss= -p " << pid; @@ -3902,12 +3918,13 @@ double SystemInformationImplementation::GetLoadAverage() /** Get the process id of the running process. */ -SystemInformation::LongLong SystemInformationImplementation::GetProcessId() +long long SystemInformationImplementation::GetProcessId() { #if defined(_WIN32) return GetCurrentProcessId(); #elif defined(__linux) || defined(__APPLE__) || defined(__OpenBSD__) || \ - defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) + defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \ + defined(__CYGWIN__) return getpid(); #else return -1; @@ -3936,7 +3953,7 @@ std::string SystemInformationImplementation::GetProgramStack(int firstFrame, int wholePath) { std::ostringstream oss; - std::string programStack = ""; + std::string programStack; #ifdef KWSYS_SYSTEMINFORMATION_HAS_DBGHELP (void)wholePath; @@ -4315,16 +4332,21 @@ size_t SystemInformationImplementation::GetAvailablePhysicalMemory() const } /** Get Cycle differences */ -SystemInformation::LongLong -SystemInformationImplementation::GetCyclesDifference(DELAY_FUNC DelayFunction, - unsigned int uiParameter) +long long SystemInformationImplementation::GetCyclesDifference( + DELAY_FUNC DelayFunction, unsigned int uiParameter) { #if defined(_MSC_VER) && (_MSC_VER >= 1400) unsigned __int64 stamp1, stamp2; +# ifdef _M_ARM64 + stamp1 = _ReadStatusReg(ARM64_PMCCNTR_EL0); + DelayFunction(uiParameter); + stamp2 = _ReadStatusReg(ARM64_PMCCNTR_EL0); +# else stamp1 = __rdtsc(); DelayFunction(uiParameter); stamp2 = __rdtsc(); +# endif return stamp2 - stamp1; #elif USE_ASM_INSTRUCTIONS @@ -4442,12 +4464,12 @@ void SystemInformationImplementation::CPUCountWindows() DWORD Length = 0; DWORD rc = pGetLogicalProcessorInformation(nullptr, &Length); assert(FALSE == rc); - (void)rc; // Silence unused variable warning in Borland C++ 5.81 + (void)rc; // Silence unused variable warning assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER); ProcInfo.resize(Length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION)); rc = pGetLogicalProcessorInformation(&ProcInfo[0], &Length); assert(rc != FALSE); - (void)rc; // Silence unused variable warning in Borland C++ 5.81 + (void)rc; // Silence unused variable warning } typedef std::vector::iterator @@ -4486,33 +4508,62 @@ unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU() const return this->NumberOfPhysicalCPU; } -/** For Mac use sysctlbyname calls to find system info */ +#if defined(__APPLE__) +static int kw_sysctlbyname_int32(const char* name, int32_t* value) +{ + size_t len = sizeof(int32_t); + int err = sysctlbyname(name, value, &len, nullptr, 0); + if (err == 0) { + assert(len == sizeof(int32_t)); + } + return err; +} + +static int kw_sysctlbyname_int64(const char* name, int64_t* value) +{ + size_t len = sizeof(int64_t); + int err = sysctlbyname(name, value, &len, nullptr, 0); + if (err == 0) { + assert(len == sizeof(int64_t)); + } + return err; +} +#endif + +/** For Apple use sysctlbyname calls to find system info */ bool SystemInformationImplementation::ParseSysCtl() { #if defined(__APPLE__) - char retBuf[128]; + char tempBuff[128]; + int32_t tempInt32 = 0; + int64_t tempInt64 = 0; int err = 0; - uint64_t value = 0; - size_t len = sizeof(value); - sysctlbyname("hw.memsize", &value, &len, nullptr, 0); - this->TotalPhysicalMemory = static_cast(value / 1048576); + size_t len; + + this->TotalPhysicalMemory = 0; + err = kw_sysctlbyname_int64("hw.memsize", &tempInt64); + if (err == 0) { + this->TotalPhysicalMemory = static_cast(tempInt64 / 1024 / 1024); + } - // Parse values for Mac this->AvailablePhysicalMemory = 0; vm_statistics_data_t vmstat; mach_msg_type_number_t count = HOST_VM_INFO_COUNT; if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) == KERN_SUCCESS) { - len = sizeof(value); - err = sysctlbyname("hw.pagesize", &value, &len, nullptr, 0); - int64_t available_memory = - (vmstat.free_count + vmstat.inactive_count) * value; - this->AvailablePhysicalMemory = - static_cast(available_memory / 1048576); + err = kw_sysctlbyname_int64("hw.pagesize", &tempInt64); + if (err == 0) { + int64_t available_memory = + (vmstat.free_count + vmstat.inactive_count) * tempInt64; + this->AvailablePhysicalMemory = + static_cast(available_memory / 1024 / 1024); + } } -# ifdef VM_SWAPUSAGE // Virtual memory. + this->AvailableVirtualMemory = 0; + this->TotalVirtualMemory = 0; +# ifdef VM_SWAPUSAGE int mib[2] = { CTL_VM, VM_SWAPUSAGE }; unsigned int miblen = static_cast(sizeof(mib) / sizeof(mib[0])); @@ -4521,78 +4572,98 @@ bool SystemInformationImplementation::ParseSysCtl() err = sysctl(mib, miblen, &swap, &len, nullptr, 0); if (err == 0) { this->AvailableVirtualMemory = - static_cast(swap.xsu_avail / 1048576); - this->TotalVirtualMemory = static_cast(swap.xsu_total / 1048576); + static_cast(swap.xsu_avail / 1024 / 1024); + this->TotalVirtualMemory = + static_cast(swap.xsu_total / 1024 / 1024); } -# else - this->AvailableVirtualMemory = 0; - this->TotalVirtualMemory = 0; # endif // CPU Info - len = sizeof(this->NumberOfPhysicalCPU); - sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, nullptr, 0); - len = sizeof(this->NumberOfLogicalCPU); - sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, nullptr, 0); - - int cores_per_package = 0; - len = sizeof(cores_per_package); - err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &len, - nullptr, 0); - // That name was not found, default to 1 - this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = - err != 0 ? 1 : static_cast(cores_per_package); + this->NumberOfPhysicalCPU = 1; + err = kw_sysctlbyname_int32("hw.physicalcpu", &tempInt32); + if (err == 0) { + this->NumberOfPhysicalCPU = tempInt32; + } - len = sizeof(value); - sysctlbyname("hw.cpufrequency", &value, &len, nullptr, 0); - this->CPUSpeedInMHz = static_cast(value) / 1000000; + this->NumberOfLogicalCPU = 1; + err = kw_sysctlbyname_int32("hw.logicalcpu", &tempInt32); + if (err == 0) { + this->NumberOfLogicalCPU = tempInt32; + } + + this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = 1; + err = kw_sysctlbyname_int32("machdep.cpu.cores_per_package", &tempInt32); + if (err == 0) { + this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = tempInt32; + } + + this->CPUSpeedInMHz = 0; + err = kw_sysctlbyname_int64("hw.cpufrequency", &tempInt64); + if (err == 0) { + this->CPUSpeedInMHz = static_cast(tempInt64) / 1000000.0f; + } // Chip family - len = sizeof(this->ChipID.Family); - // Seems only the intel chips will have this name so if this fails it is - // probably a PPC machine - err = - sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, nullptr, 0); + // Seems only the Intel chips will have this name so if this fails it is + // a PowerPC or ARM, or something unknown + this->ChipID.Vendor = ""; + this->ChipID.Family = 0; + this->ChipID.Model = 0; + this->ChipID.Revision = 0; + err = kw_sysctlbyname_int32("machdep.cpu.family", &tempInt32); if (err != 0) // Go back to names we know but are less descriptive { - this->ChipID.Family = 0; - ::memset(retBuf, 0, 128); - len = 32; - err = sysctlbyname("hw.machine", &retBuf, &len, nullptr, 0); - std::string machineBuf(retBuf); - if (machineBuf.find_first_of("Power") != std::string::npos) { - this->ChipID.Vendor = "IBM"; - len = sizeof(this->ChipID.Family); - err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len, nullptr, 0); - len = sizeof(this->ChipID.Model); - err = - sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len, nullptr, 0); - this->FindManufacturer(); + ::memset(tempBuff, 0, sizeof(tempBuff)); + len = sizeof(tempBuff) - 1; // leave a byte for null termination + err = sysctlbyname("hw.machine", &tempBuff, &len, nullptr, 0); + if (err == 0) { + std::string machineBuf(tempBuff); + if (machineBuf.find_first_of("Power") != std::string::npos) { + this->ChipID.Vendor = "IBM"; + + err = kw_sysctlbyname_int32("hw.cputype", &tempInt32); + if (err == 0) { + this->ChipID.Family = tempInt32; + } + + err = kw_sysctlbyname_int32("hw.cpusubtype", &tempInt32); + if (err == 0) { + this->ChipID.Model = tempInt32; + } + + this->FindManufacturer(); + } else if (machineBuf.find_first_of("arm64") != std::string::npos) { + this->ChipID.Vendor = "Apple"; + + this->FindManufacturer(); + } + } + } else { + // Should be an Intel Chip. + err = kw_sysctlbyname_int32("machdep.cpu.family", &tempInt32); + if (err == 0) { + this->ChipID.Family = tempInt32; } - } else // Should be an Intel Chip. - { - len = sizeof(this->ChipID.Family); - err = sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, - nullptr, 0); - ::memset(retBuf, 0, 128); - len = 128; - err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, nullptr, 0); // Chip Vendor - this->ChipID.Vendor = retBuf; + ::memset(tempBuff, 0, sizeof(tempBuff)); + len = sizeof(tempBuff) - 1; // leave a byte for null termination + err = sysctlbyname("machdep.cpu.vendor", tempBuff, &len, nullptr, 0); + if (err == 0) { + this->ChipID.Vendor = tempBuff; + } this->FindManufacturer(); // Chip Model - len = sizeof(value); - err = sysctlbyname("machdep.cpu.model", &value, &len, nullptr, 0); - this->ChipID.Model = static_cast(value); + err = kw_sysctlbyname_int32("machdep.cpu.model", &tempInt32); + if (err == 0) { + this->ChipID.Model = tempInt32; + } // Chip Stepping - len = sizeof(value); - value = 0; - err = sysctlbyname("machdep.cpu.stepping", &value, &len, nullptr, 0); - if (!err) { - this->ChipID.Revision = static_cast(value); + err = kw_sysctlbyname_int32("machdep.cpu.stepping", &tempInt32); + if (err == 0) { + this->ChipID.Revision = tempInt32; } // feature string @@ -4615,36 +4686,36 @@ bool SystemInformationImplementation::ParseSysCtl() len = allocSize - 2; // keep space for leading and trailing space err = sysctlbyname("machdep.cpu.features", buf + 1, &len, nullptr, 0); } - if (!err && buf && len) { + if (err == 0 && buf && len) { // now we can match every flags as space + flag + space buf[len + 1] = ' '; std::string cpuflags(buf, len + 2); - if ((cpuflags.find(" FPU ") != std::string::npos)) { + if (cpuflags.find(" FPU ") != std::string::npos) { this->Features.HasFPU = true; } - if ((cpuflags.find(" TSC ") != std::string::npos)) { + if (cpuflags.find(" TSC ") != std::string::npos) { this->Features.HasTSC = true; } - if ((cpuflags.find(" MMX ") != std::string::npos)) { + if (cpuflags.find(" MMX ") != std::string::npos) { this->Features.HasMMX = true; } - if ((cpuflags.find(" SSE ") != std::string::npos)) { + if (cpuflags.find(" SSE ") != std::string::npos) { this->Features.HasSSE = true; } - if ((cpuflags.find(" SSE2 ") != std::string::npos)) { + if (cpuflags.find(" SSE2 ") != std::string::npos) { this->Features.HasSSE2 = true; } - if ((cpuflags.find(" APIC ") != std::string::npos)) { + if (cpuflags.find(" APIC ") != std::string::npos) { this->Features.HasAPIC = true; } - if ((cpuflags.find(" CMOV ") != std::string::npos)) { + if (cpuflags.find(" CMOV ") != std::string::npos) { this->Features.HasCMOV = true; } - if ((cpuflags.find(" MTRR ") != std::string::npos)) { + if (cpuflags.find(" MTRR ") != std::string::npos) { this->Features.HasMTRR = true; } - if ((cpuflags.find(" ACPI ") != std::string::npos)) { + if (cpuflags.find(" ACPI ") != std::string::npos) { this->Features.HasACPI = true; } } @@ -4652,21 +4723,29 @@ bool SystemInformationImplementation::ParseSysCtl() } // brand string - ::memset(retBuf, 0, sizeof(retBuf)); - len = sizeof(retBuf); - err = sysctlbyname("machdep.cpu.brand_string", retBuf, &len, nullptr, 0); - if (!err) { - this->ChipID.ProcessorName = retBuf; - this->ChipID.ModelName = retBuf; + this->ChipID.ProcessorName = ""; + this->ChipID.ModelName = ""; + ::memset(tempBuff, 0, sizeof(tempBuff)); + len = sizeof(tempBuff) - 1; // leave a byte for null termination + err = sysctlbyname("machdep.cpu.brand_string", tempBuff, &len, nullptr, 0); + if (err == 0) { + this->ChipID.ProcessorName = tempBuff; + this->ChipID.ModelName = tempBuff; } - // Cache size - len = sizeof(value); - err = sysctlbyname("hw.l1icachesize", &value, &len, nullptr, 0); - this->Features.L1CacheSize = static_cast(value); - len = sizeof(value); - err = sysctlbyname("hw.l2cachesize", &value, &len, nullptr, 0); - this->Features.L2CacheSize = static_cast(value); + // L1 Cache size + this->Features.L1CacheSize = 0; + err = kw_sysctlbyname_int64("hw.l1icachesize", &tempInt64); + if (err == 0) { + this->Features.L1CacheSize = static_cast(tempInt64); + } + + // L2 Cache size + this->Features.L2CacheSize = 0; + err = kw_sysctlbyname_int64("hw.l2cachesize", &tempInt64); + if (err == 0) { + this->Features.L2CacheSize = static_cast(tempInt64); + } return true; #else @@ -4681,7 +4760,7 @@ std::string SystemInformationImplementation::ExtractValueFromSysCtl( size_t pos = this->SysCtlBuffer.find(word); if (pos != std::string::npos) { pos = this->SysCtlBuffer.find(": ", pos); - size_t pos2 = this->SysCtlBuffer.find("\n", pos); + size_t pos2 = this->SysCtlBuffer.find('\n', pos); if (pos != std::string::npos && pos2 != std::string::npos) { return this->SysCtlBuffer.substr(pos + 2, pos2 - pos - 2); } @@ -5493,13 +5572,13 @@ void SystemInformationImplementation::TrimNewline(std::string& output) { // remove \r std::string::size_type pos = 0; - while ((pos = output.find("\r", pos)) != std::string::npos) { + while ((pos = output.find('\r', pos)) != std::string::npos) { output.erase(pos); } // remove \n pos = 0; - while ((pos = output.find("\n", pos)) != std::string::npos) { + while ((pos = output.find('\n', pos)) != std::string::npos) { output.erase(pos); } } diff --git a/Utilities/KWSys/vtksys/SystemInformation.hxx.in b/Utilities/KWSys/vtksys/SystemInformation.hxx.in index fc42e9dc7..c8efd51d0 100644 --- a/Utilities/KWSys/vtksys/SystemInformation.hxx.in +++ b/Utilities/KWSys/vtksys/SystemInformation.hxx.in @@ -15,13 +15,6 @@ class SystemInformationImplementation; class @KWSYS_NAMESPACE@_EXPORT SystemInformation { -#if @KWSYS_USE_LONG_LONG@ - typedef long long LongLong; -#elif @KWSYS_USE___INT64@ - typedef __int64 LongLong; -#else -# error "No Long Long" -#endif friend class SystemInformationImplementation; SystemInformationImplementation* Implementation; @@ -104,7 +97,7 @@ public: bool DoesCPUSupportCPUID(); // Retrieve id of the current running process - LongLong GetProcessId(); + long long GetProcessId(); // Retrieve memory information in MiB. size_t GetTotalVirtualMemory(); @@ -120,7 +113,7 @@ public: // Retrieve amount of physical memory installed on the system in KiB // units. - LongLong GetHostMemoryTotal(); + long long GetHostMemoryTotal(); // Get total system RAM in units of KiB available colectivley to all // processes in a process group. An example of a process group @@ -128,7 +121,7 @@ public: // parallel. The amount of memory reported may differ from the host // total if a host wide resource limit is applied. Such reource limits // are reported to us via an application specified environment variable. - LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName = nullptr); + long long GetHostMemoryAvailable(const char* hostLimitEnvVarName = nullptr); // Get total system RAM in units of KiB available to this process. // This may differ from the host available if a per-process resource @@ -136,14 +129,14 @@ public: // system via rlimit API. Resource limits that are not imposed via // rlimit API may be reported to us via an application specified // environment variable. - LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName = nullptr, - const char* procLimitEnvVarName = nullptr); + long long GetProcMemoryAvailable(const char* hostLimitEnvVarName = nullptr, + const char* procLimitEnvVarName = nullptr); // Get the system RAM used by all processes on the host, in units of KiB. - LongLong GetHostMemoryUsed(); + long long GetHostMemoryUsed(); // Get system RAM used by this process id in units of KiB. - LongLong GetProcMemoryUsed(); + long long GetProcMemoryUsed(); // Return the load average of the machine or -0.0 if it cannot // be determined. diff --git a/Utilities/KWSys/vtksys/SystemTools.cxx b/Utilities/KWSys/vtksys/SystemTools.cxx index e073cbf91..6144d9c04 100644 --- a/Utilities/KWSys/vtksys/SystemTools.cxx +++ b/Utilities/KWSys/vtksys/SystemTools.cxx @@ -6,9 +6,7 @@ # define _XOPEN_SOURCE_EXTENDED #endif -#if defined(_WIN32) && \ - (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || \ - defined(__MINGW32__)) +#if defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__)) # define KWSYS_WINDOWS_DIRS #else # if defined(__SUNPRO_CC) @@ -24,6 +22,7 @@ #include KWSYS_HEADER(Encoding.h) #include KWSYS_HEADER(Encoding.hxx) +#include #include #include #include @@ -49,27 +48,27 @@ # pragma set woff 1375 /* base class destructor not virtual */ #endif -#include -#include +#include +#include #ifdef __QNX__ # include /* for malloc/free on QNX */ #endif -#include -#include -#include -#include +#include +#include +#include +#include #if defined(_WIN32) && !defined(_MSC_VER) && defined(__GNUC__) # include /* for strcasecmp */ #endif #ifdef _MSC_VER -# define umask _umask // Note this is still umask on Borland +# define umask _umask #endif // support for realpath call #ifndef _WIN32 -# include +# include # include # include # include @@ -80,7 +79,7 @@ # include # include # endif -# include /* sigprocmask */ +# include /* sigprocmask */ #endif #ifdef __linux @@ -97,19 +96,12 @@ # if defined(_MSC_VER) && _MSC_VER >= 1800 # define KWSYS_WINDOWS_DEPRECATED_GetVersionEx # endif -#elif defined(__CYGWIN__) -# include -# undef _WIN32 #endif #if !KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H extern char** environ; #endif -#ifdef __CYGWIN__ -# include -#endif - // getpwnam doesn't exist on Windows and Cray Xt3/Catamount // same for TIOCGWINSZ #if defined(_WIN32) || defined(__LIBCATAMOUNT__) || \ @@ -153,9 +145,7 @@ public: } #endif -#if defined(_WIN32) && \ - (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || \ - defined(__MINGW32__)) +#if defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__)) # include # include # define _unlink unlink @@ -169,13 +159,6 @@ public: #else # define KWSYS_SYSTEMTOOLS_MAXPATH 16384 #endif -#if defined(__WATCOMC__) -# include -# define _mkdir mkdir -# define _rmdir rmdir -# define _getcwd getcwd -# define _chdir chdir -#endif #if defined(__BEOS__) && !defined(__ZETA__) # include @@ -258,11 +241,7 @@ inline const char* Getcwd(char* buf, unsigned int len) } inline int Chdir(const std::string& dir) { -# if defined(__BORLANDC__) - return chdir(dir.c_str()); -# else return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str()); -# endif } inline void Realpath(const std::string& path, std::string& resolved_path, std::string* errorMessage = 0) @@ -498,6 +477,9 @@ public: bool no_system_path = false); }; +// Do NOT initialize. Default initialization to zero is necessary. +static SystemToolsStatic* SystemToolsStatics; + #ifdef _WIN32 std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn) { @@ -572,7 +554,7 @@ std::string SystemToolsStatic::GetActualCaseForPathCached(std::string const& p) { // Check to see if actual case has already been called // for this path, and the result is stored in the PathCaseMap - auto& pcm = SystemTools::Statics->PathCaseMap; + auto& pcm = SystemToolsStatics->PathCaseMap; { auto itr = pcm.find(p); if (itr != pcm.end()) { @@ -629,7 +611,7 @@ const char* SystemToolsStatic::GetEnvBuffered(const char* key) { std::string env; if (SystemTools::GetEnv(key, env)) { - std::string& menv = SystemTools::Statics->EnvMap[key]; + std::string& menv = SystemToolsStatics->EnvMap[key]; if (menv != env) { menv = std::move(env); } @@ -889,8 +871,12 @@ const char* SystemTools::GetExecutableExtension() FILE* SystemTools::Fopen(const std::string& file, const char* mode) { #ifdef _WIN32 + // Remove any 'e', which is supported on UNIX, but not Windows. + std::wstring trimmedMode = Encoding::ToWide(mode); + trimmedMode.erase(std::remove(trimmedMode.begin(), trimmedMode.end(), L'e'), + trimmedMode.end()); return _wfopen(Encoding::ToWindowsExtendedPath(file).c_str(), - Encoding::ToWide(mode).c_str()); + trimmedMode.c_str()); #else return fopen(file.c_str(), mode); #endif @@ -929,15 +915,9 @@ bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode) } topdir = dir; if (Mkdir(topdir, mode) != 0) { - // There is a bug in the Borland Run time library which makes MKDIR - // return EACCES when it should return EEXISTS // if it is some other error besides directory exists // then return false - if ((errno != EEXIST) -#ifdef __BORLANDC__ - && (errno != EACCES) -#endif - ) { + if (errno != EEXIST) { return false; } } @@ -1303,15 +1283,7 @@ bool SystemTools::PathExists(const std::string& path) if (path.empty()) { return false; } -#if defined(__CYGWIN__) - // Convert path to native windows path if possible. - char winpath[MAX_PATH]; - if (SystemTools::PathCygwinToWin32(path.c_str(), winpath)) { - return (GetFileAttributesA(winpath) != INVALID_FILE_ATTRIBUTES); - } - struct stat st; - return lstat(path.c_str(), &st) == 0; -#elif defined(_WIN32) +#if defined(_WIN32) return (GetFileAttributesW(Encoding::ToWindowsExtendedPath(path).c_str()) != INVALID_FILE_ATTRIBUTES); #else @@ -1333,14 +1305,7 @@ bool SystemTools::FileExists(const std::string& filename) if (filename.empty()) { return false; } -#if defined(__CYGWIN__) - // Convert filename to native windows path if possible. - char winpath[MAX_PATH]; - if (SystemTools::PathCygwinToWin32(filename.c_str(), winpath)) { - return (GetFileAttributesA(winpath) != INVALID_FILE_ATTRIBUTES); - } - return access(filename.c_str(), R_OK) == 0; -#elif defined(_WIN32) +#if defined(_WIN32) DWORD attr = GetFileAttributesW(Encoding::ToWindowsExtendedPath(filename).c_str()); if (attr == INVALID_FILE_ATTRIBUTES) { @@ -1440,37 +1405,15 @@ int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf) // long paths, but _wstat64 rejects paths with '?' in them, thinking // they are wildcards. std::wstring const& wpath = Encoding::ToWide(path); -# if defined(__BORLANDC__) - return _wstati64(wpath.c_str(), buf); -# else return _wstat64(wpath.c_str(), buf); -# endif #else return stat(path.c_str(), buf); #endif } -#ifdef __CYGWIN__ -bool SystemTools::PathCygwinToWin32(const char* path, char* win32_path) -{ - auto itr = SystemTools::Statics->Cyg2Win32Map.find(path); - if (itr != SystemTools::Statics->Cyg2Win32Map.end()) { - strncpy(win32_path, itr->second.c_str(), MAX_PATH); - } else { - if (cygwin_conv_path(CCP_POSIX_TO_WIN_A, path, win32_path, MAX_PATH) != - 0) { - win32_path[0] = 0; - } - SystemTools::Statics->Cyg2Win32Map.insert( - SystemToolsStatic::StringMap::value_type(path, win32_path)); - } - return win32_path[0] != 0; -} -#endif - bool SystemTools::Touch(const std::string& filename, bool create) { - if (!SystemTools::PathExists(filename)) { + if (!SystemTools::FileExists(filename)) { if (create) { FILE* file = Fopen(filename, "a+b"); if (file) { @@ -1901,7 +1844,7 @@ std::vector SystemTools::SplitString(const std::string& p, paths.emplace_back("/"); } std::string::size_type pos1 = 0; - std::string::size_type pos2 = path.find(sep, pos1 + 1); + std::string::size_type pos2 = path.find(sep, pos1); while (pos2 != std::string::npos) { paths.push_back(path.substr(pos1, pos2 - pos1)); pos1 = pos2 + 1; @@ -2110,7 +2053,7 @@ std::string SystemTools::ConvertToUnixOutputPath(const std::string& path) ret.erase(pos, 1); } // escape spaces and () in the path - if (ret.find_first_of(" ") != std::string::npos) { + if (ret.find_first_of(' ') != std::string::npos) { std::string result; char lastch = 1; for (const char* ch = ret.c_str(); *ch != '\0'; ++ch) { @@ -2508,8 +2451,8 @@ bool SystemTools::CopyADirectory(const std::string& source, return false; } for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) { - if (strcmp(dir.GetFile(static_cast(fileNum)), ".") && - strcmp(dir.GetFile(static_cast(fileNum)), "..")) { + if (strcmp(dir.GetFile(static_cast(fileNum)), ".") != 0 && + strcmp(dir.GetFile(static_cast(fileNum)), "..") != 0) { std::string fullPath = source; fullPath += "/"; fullPath += dir.GetFile(static_cast(fileNum)); @@ -2671,8 +2614,8 @@ bool SystemTools::RemoveADirectory(const std::string& source) dir.Load(source); size_t fileNum; for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) { - if (strcmp(dir.GetFile(static_cast(fileNum)), ".") && - strcmp(dir.GetFile(static_cast(fileNum)), "..")) { + if (strcmp(dir.GetFile(static_cast(fileNum)), ".") != 0 && + strcmp(dir.GetFile(static_cast(fileNum)), "..") != 0) { std::string fullPath = source; fullPath += "/"; fullPath += dir.GetFile(static_cast(fileNum)); @@ -2804,7 +2747,7 @@ std::string SystemTools::FindProgram(const std::string& name, for (std::string const& ext : extensions) { tryPath = name; tryPath += ext; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -2812,7 +2755,7 @@ std::string SystemTools::FindProgram(const std::string& name, #endif // now try just the name - if (SystemTools::FileExists(name, true)) { + if (SystemTools::FileIsExecutable(name)) { return SystemTools::CollapseFullPath(name); } // now construct the path @@ -2842,7 +2785,7 @@ std::string SystemTools::FindProgram(const std::string& name, tryPath = p; tryPath += name; tryPath += ext; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -2850,7 +2793,7 @@ std::string SystemTools::FindProgram(const std::string& name, // now try it without them tryPath = p; tryPath += name; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -3005,6 +2948,15 @@ bool SystemTools::FileIsDirectory(const std::string& inName) } } +bool SystemTools::FileIsExecutable(const std::string& name) +{ +#if defined(_WIN32) + return SystemTools::FileExists(name, true); +#else + return !FileIsDirectory(name) && TestFileAccess(name, TEST_FILE_EXECUTE); +#endif +} + bool SystemTools::FileIsSymlink(const std::string& name) { #if defined(_WIN32) @@ -3114,16 +3066,14 @@ int SystemTools::ChangeDirectory(const std::string& dir) return Chdir(dir); } -std::string SystemTools::GetCurrentWorkingDirectory(bool collapse) +std::string SystemTools::GetCurrentWorkingDirectory() { char buf[2048]; const char* cwd = Getcwd(buf, 2048); std::string path; if (cwd) { path = cwd; - } - if (collapse) { - return SystemTools::CollapseFullPath(path); + SystemTools::ConvertToUnixSlashes(path); } return path; } @@ -3143,7 +3093,7 @@ bool SystemTools::SplitProgramPath(const std::string& in_name, SystemTools::ConvertToUnixSlashes(dir); if (!SystemTools::FileIsDirectory(dir)) { - std::string::size_type slashPos = dir.rfind("/"); + std::string::size_type slashPos = dir.rfind('/'); if (slashPos != std::string::npos) { file = dir.substr(slashPos + 1); dir.resize(slashPos); @@ -3171,7 +3121,7 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut, failures.push_back(self); SystemTools::ConvertToUnixSlashes(self); self = SystemTools::FindProgram(self); - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { if (buildDir) { std::string intdir = "."; #ifdef CMAKE_INTDIR @@ -3186,14 +3136,14 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut, } } if (installPrefix) { - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { failures.push_back(self); self = installPrefix; self += "/bin/"; self += exeName; } } - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { failures.push_back(self); std::ostringstream msg; msg << "Can not find the command line program "; @@ -3215,11 +3165,6 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut, return true; } -std::string SystemTools::CollapseFullPath(const std::string& in_relative) -{ - return SystemTools::CollapseFullPath(in_relative, nullptr); -} - #if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP void SystemTools::AddTranslationPath(const std::string& a, const std::string& b) @@ -3244,7 +3189,7 @@ void SystemTools::AddTranslationPath(const std::string& a, path_b += '/'; } if (!(path_a == path_b)) { - SystemTools::Statics->TranslationMap.insert( + SystemToolsStatics->TranslationMap.insert( SystemToolsStatic::StringMap::value_type(std::move(path_a), std::move(path_b))); } @@ -3274,7 +3219,7 @@ void SystemTools::CheckTranslationPath(std::string& path) // In case a file was specified we still have to go through this: // Now convert any path found in the table back to the one desired: - for (auto const& pair : SystemTools::Statics->TranslationMap) { + for (auto const& pair : SystemToolsStatics->TranslationMap) { // We need to check of the path is a substring of the other path if (path.compare(0, pair.first.size(), pair.first) == 0) { path = path.replace(0, pair.first.size(), pair.second); @@ -3309,25 +3254,10 @@ static void SystemToolsAppendComponents( } } -std::string SystemTools::CollapseFullPath(const std::string& in_path, - const char* in_base) -{ - // Use the current working directory as a base path. - char buf[2048]; - const char* res_in_base = in_base; - if (!res_in_base) { - if (const char* cwd = Getcwd(buf, 2048)) { - res_in_base = cwd; - } else { - res_in_base = ""; - } - } +namespace { - return SystemTools::CollapseFullPath(in_path, std::string(res_in_base)); -} - -std::string SystemTools::CollapseFullPath(const std::string& in_path, - const std::string& in_base) +std::string CollapseFullPathImpl(std::string const& in_path, + std::string const* in_base) { // Collect the output path components. std::vector out_components; @@ -3340,8 +3270,15 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path, // If the input path is relative, start with a base path. if (path_components[0].empty()) { std::vector base_components; - // Use the given base path. - SystemTools::SplitPath(in_base, base_components); + + if (in_base) { + // Use the given base path. + SystemTools::SplitPath(*in_base, base_components); + } else { + // Use the current working directory as a base path. + std::string cwd = SystemTools::GetCurrentWorkingDirectory(); + SystemTools::SplitPath(cwd, base_components); + } // Append base path components to the output path. out_components.push_back(base_components[0]); @@ -3374,12 +3311,34 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path, SystemTools::CheckTranslationPath(newPath); #endif #ifdef _WIN32 - newPath = SystemTools::Statics->GetActualCaseForPathCached(newPath); + newPath = SystemToolsStatics->GetActualCaseForPathCached(newPath); SystemTools::ConvertToUnixSlashes(newPath); #endif // Return the reconstructed path. return newPath; } +} + +std::string SystemTools::CollapseFullPath(std::string const& in_path) +{ + return CollapseFullPathImpl(in_path, nullptr); +} + +std::string SystemTools::CollapseFullPath(std::string const& in_path, + const char* in_base) +{ + if (!in_base) { + return CollapseFullPathImpl(in_path, nullptr); + } + std::string tmp_base = in_base; + return CollapseFullPathImpl(in_path, &tmp_base); +} + +std::string SystemTools::CollapseFullPath(std::string const& in_path, + std::string const& in_base) +{ + return CollapseFullPathImpl(in_path, &in_base); +} // compute the relative path from here to there std::string SystemTools::RelativePath(const std::string& local, @@ -3692,7 +3651,7 @@ std::string SystemTools::GetFilenamePath(const std::string& filename) std::string fn = filename; SystemTools::ConvertToUnixSlashes(fn); - std::string::size_type slash_pos = fn.rfind("/"); + std::string::size_type slash_pos = fn.rfind('/'); if (slash_pos == 0) { return "/"; } @@ -4601,10 +4560,8 @@ std::string SystemTools::DecodeURL(const std::string& url) } // ---------------------------------------------------------------------- -// These must NOT be initialized. Default initialization to zero is -// necessary. +// Do NOT initialize. Default initialization to zero is necessary. static unsigned int SystemToolsManagerCount; -SystemToolsStatic* SystemTools::Statics; // SystemToolsManager manages the SystemTools singleton. // SystemToolsManager should be included in any translation unit @@ -4647,7 +4604,7 @@ void SystemTools::ClassInitialize() #endif // Create statics singleton instance - SystemTools::Statics = new SystemToolsStatic; + SystemToolsStatics = new SystemToolsStatic; #if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP // Add some special translation paths for unix. These are not added @@ -4697,7 +4654,7 @@ void SystemTools::ClassInitialize() void SystemTools::ClassFinalize() { - delete SystemTools::Statics; + delete SystemToolsStatics; } } // namespace KWSYS_NAMESPACE diff --git a/Utilities/KWSys/vtksys/SystemTools.hxx.in b/Utilities/KWSys/vtksys/SystemTools.hxx.in index d4a93faf7..74dc17651 100644 --- a/Utilities/KWSys/vtksys/SystemTools.hxx.in +++ b/Utilities/KWSys/vtksys/SystemTools.hxx.in @@ -67,7 +67,7 @@ static SystemToolsManager SystemToolsManagerInstance; // combined using the | operator. typedef int TestFilePermissions; #if defined(_WIN32) && !defined(__CYGWIN__) -// On Windows (VC and Borland), no system header defines these constants... +// On Windows (VC), no system header defines these constants... static const TestFilePermissions TEST_FILE_OK = 0; static const TestFilePermissions TEST_FILE_READ = 4; static const TestFilePermissions TEST_FILE_WRITE = 2; @@ -317,11 +317,7 @@ public: * Cross platform wrapper for stat struct */ #if defined(_WIN32) && !defined(__CYGWIN__) -# if defined(__BORLANDC__) - typedef struct stati64 Stat_t; -# else typedef struct _stat64 Stat_t; -# endif #else typedef struct stat Stat_t; #endif @@ -335,15 +331,6 @@ public: static int Stat(const char* path, Stat_t* buf); static int Stat(const std::string& path, Stat_t* buf); -/** - * Converts Cygwin path to Win32 path. Uses dictionary container for - * caching and calls to cygwin_conv_to_win32_path from Cygwin dll - * for actual translation. Returns true on success, else false. - */ -#ifdef __CYGWIN__ - static bool PathCygwinToWin32(const char* path, char* win32_path); -#endif - /** * Return file length */ @@ -411,11 +398,11 @@ public: * (which defaults to the current working directory). The full path * is returned. */ - static std::string CollapseFullPath(const std::string& in_relative); - static std::string CollapseFullPath(const std::string& in_relative, + static std::string CollapseFullPath(std::string const& in_path); + static std::string CollapseFullPath(std::string const& in_path, const char* in_base); - static std::string CollapseFullPath(const std::string& in_relative, - const std::string& in_base); + static std::string CollapseFullPath(std::string const& in_path, + std::string const& in_base); /** * Get the real path for a given path, removing all symlinks. In @@ -549,12 +536,13 @@ public: */ /** - * Open a file considering unicode. + * Open a file considering unicode. On Windows, if 'e' is present in + * mode it is first discarded. */ static FILE* Fopen(const std::string& file, const char* mode); /** - * Visual C++ does not define mode_t (note that Borland does, however). + * Visual C++ does not define mode_t. */ #if defined(_MSC_VER) typedef unsigned short mode_t; @@ -676,6 +664,11 @@ public: */ static bool FileIsDirectory(const std::string& name); + /** + * Return true if the file is an executable + */ + static bool FileIsExecutable(const std::string& name); + /** * Return true if the file is a symlink */ @@ -869,7 +862,7 @@ public: /** * Get current working directory CWD */ - static std::string GetCurrentWorkingDirectory(bool collapse = true); + static std::string GetCurrentWorkingDirectory(); /** * Change directory to the directory specified @@ -981,7 +974,6 @@ private: return &SystemToolsManagerInstance; } - static SystemToolsStatic* Statics; friend class SystemToolsStatic; friend class SystemToolsManager; }; diff --git a/Utilities/KWSys/vtksys/hash_fun.hxx.in b/Utilities/KWSys/vtksys/hash_fun.hxx.in deleted file mode 100644 index 8626c2aa2..000000000 --- a/Utilities/KWSys/vtksys/hash_fun.hxx.in +++ /dev/null @@ -1,166 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -/* - * Copyright (c) 1996 - * Silicon Graphics Computer Systems, Inc. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Silicon Graphics makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - * - * Copyright (c) 1994 - * Hewlett-Packard Company - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Hewlett-Packard Company makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ -#ifndef @KWSYS_NAMESPACE@_hash_fun_hxx -#define @KWSYS_NAMESPACE@_hash_fun_hxx - -#include <@KWSYS_NAMESPACE@/Configure.hxx> - -#include // size_t -#include - -namespace @KWSYS_NAMESPACE@ { - -template -struct hash -{ -}; - -inline size_t _stl_hash_string(const char* __s) -{ - unsigned long __h = 0; - for (; *__s; ++__s) - __h = 5 * __h + *__s; - - return size_t(__h); -} - -template <> -struct hash -{ - size_t operator()(const char* __s) const { return _stl_hash_string(__s); } -}; - -template <> -struct hash -{ - size_t operator()(const char* __s) const { return _stl_hash_string(__s); } -}; - -template <> -struct hash -{ - size_t operator()(const std::string& __s) const - { - return _stl_hash_string(__s.c_str()); - } -}; - -#if !defined(__BORLANDC__) -template <> -struct hash -{ - size_t operator()(const std::string& __s) const - { - return _stl_hash_string(__s.c_str()); - } -}; -#endif - -template <> -struct hash -{ - size_t operator()(char __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(unsigned char __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(unsigned char __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(short __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(unsigned short __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(int __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(unsigned int __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(long __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(unsigned long __x) const { return __x; } -}; - -// use long long or __int64 -#if @KWSYS_USE_LONG_LONG@ -template <> -struct hash -{ - size_t operator()(long long __x) const { return __x; } -}; - -template <> -struct hash -{ - size_t operator()(unsigned long long __x) const { return __x; } -}; -#elif @KWSYS_USE___INT64@ -template <> -struct hash<__int64> -{ - size_t operator()(__int64 __x) const { return __x; } -}; -template <> -struct hash -{ - size_t operator()(unsigned __int64 __x) const { return __x; } -}; -#endif // use long long or __int64 - -} // namespace @KWSYS_NAMESPACE@ - -#endif diff --git a/Utilities/KWSys/vtksys/hash_map.hxx.in b/Utilities/KWSys/vtksys/hash_map.hxx.in deleted file mode 100644 index 5f04e9c16..000000000 --- a/Utilities/KWSys/vtksys/hash_map.hxx.in +++ /dev/null @@ -1,423 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -/* - * Copyright (c) 1996 - * Silicon Graphics Computer Systems, Inc. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Silicon Graphics makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - * - * Copyright (c) 1994 - * Hewlett-Packard Company - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Hewlett-Packard Company makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ -#ifndef @KWSYS_NAMESPACE@_hash_map_hxx -#define @KWSYS_NAMESPACE@_hash_map_hxx - -#include <@KWSYS_NAMESPACE@/hashtable.hxx> - -#include <@KWSYS_NAMESPACE@/hash_fun.hxx> - -#include // equal_to - -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4284) -# pragma warning(disable : 4786) -#endif - -#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) -# pragma set woff 1174 -# pragma set woff 1375 -#endif - -namespace @KWSYS_NAMESPACE@ { - -// select1st is an extension: it is not part of the standard. -template -struct hash_select1st -{ - const T1& operator()(const std::pair& __x) const - { - return __x.first; - } -}; - -// Forward declaration of equality operator; needed for friend declaration. - -template , - class _EqualKey = std::equal_to<_Key>, - class _Alloc = std::allocator > -class hash_map; - -template -bool operator==(const hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>&, - const hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>&); - -template -class hash_map -{ -private: - typedef hashtable, _Key, _HashFcn, - hash_select1st, _EqualKey, _Alloc> - _Ht; - _Ht _M_ht; - -public: - typedef typename _Ht::key_type key_type; - typedef _Tp data_type; - typedef _Tp mapped_type; - typedef typename _Ht::value_type value_type; - typedef typename _Ht::hasher hasher; - typedef typename _Ht::key_equal key_equal; - - typedef typename _Ht::size_type size_type; - typedef typename _Ht::difference_type difference_type; - typedef typename _Ht::pointer pointer; - typedef typename _Ht::const_pointer const_pointer; - typedef typename _Ht::reference reference; - typedef typename _Ht::const_reference const_reference; - - typedef typename _Ht::iterator iterator; - typedef typename _Ht::const_iterator const_iterator; - - typedef typename _Ht::allocator_type allocator_type; - - hasher hash_funct() const { return _M_ht.hash_funct(); } - key_equal key_eq() const { return _M_ht.key_eq(); } - allocator_type get_allocator() const { return _M_ht.get_allocator(); } - -public: - hash_map() - : _M_ht(100, hasher(), key_equal(), allocator_type()) - { - } - explicit hash_map(size_type __n) - : _M_ht(__n, hasher(), key_equal(), allocator_type()) - { - } - hash_map(size_type __n, const hasher& __hf) - : _M_ht(__n, __hf, key_equal(), allocator_type()) - { - } - hash_map(size_type __n, const hasher& __hf, const key_equal& __eql, - const allocator_type& __a = allocator_type()) - : _M_ht(__n, __hf, __eql, __a) - { - } - - template - hash_map(_InputIterator __f, _InputIterator __l) - : _M_ht(100, hasher(), key_equal(), allocator_type()) - { - _M_ht.insert_unique(__f, __l); - } - template - hash_map(_InputIterator __f, _InputIterator __l, size_type __n) - : _M_ht(__n, hasher(), key_equal(), allocator_type()) - { - _M_ht.insert_unique(__f, __l); - } - template - hash_map(_InputIterator __f, _InputIterator __l, size_type __n, - const hasher& __hf) - : _M_ht(__n, __hf, key_equal(), allocator_type()) - { - _M_ht.insert_unique(__f, __l); - } - template - hash_map(_InputIterator __f, _InputIterator __l, size_type __n, - const hasher& __hf, const key_equal& __eql, - const allocator_type& __a = allocator_type()) - : _M_ht(__n, __hf, __eql, __a) - { - _M_ht.insert_unique(__f, __l); - } - -public: - size_type size() const { return _M_ht.size(); } - size_type max_size() const { return _M_ht.max_size(); } - bool empty() const { return _M_ht.empty(); } - void swap(hash_map& __hs) { _M_ht.swap(__hs._M_ht); } - - friend bool operator==<>(const hash_map&, const hash_map&); - - iterator begin() { return _M_ht.begin(); } - iterator end() { return _M_ht.end(); } - const_iterator begin() const { return _M_ht.begin(); } - const_iterator end() const { return _M_ht.end(); } - -public: - std::pair insert(const value_type& __obj) - { - return _M_ht.insert_unique(__obj); - } - template - void insert(_InputIterator __f, _InputIterator __l) - { - _M_ht.insert_unique(__f, __l); - } - std::pair insert_noresize(const value_type& __obj) - { - return _M_ht.insert_unique_noresize(__obj); - } - - iterator find(const key_type& __key) { return _M_ht.find(__key); } - const_iterator find(const key_type& __key) const - { - return _M_ht.find(__key); - } - - _Tp& operator[](const key_type& __key) - { - return _M_ht.find_or_insert(value_type(__key, _Tp())).second; - } - - size_type count(const key_type& __key) const { return _M_ht.count(__key); } - - std::pair equal_range(const key_type& __key) - { - return _M_ht.equal_range(__key); - } - std::pair equal_range( - const key_type& __key) const - { - return _M_ht.equal_range(__key); - } - - size_type erase(const key_type& __key) { return _M_ht.erase(__key); } - void erase(iterator __it) { _M_ht.erase(__it); } - void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); } - void clear() { _M_ht.clear(); } - - void resize(size_type __hint) { _M_ht.resize(__hint); } - size_type bucket_count() const { return _M_ht.bucket_count(); } - size_type max_bucket_count() const { return _M_ht.max_bucket_count(); } - size_type elems_in_bucket(size_type __n) const - { - return _M_ht.elems_in_bucket(__n); - } -}; - -template -bool operator==(const hash_map<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm1, - const hash_map<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm2) -{ - return __hm1._M_ht == __hm2._M_ht; -} - -template -inline bool operator!=( - const hash_map<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm1, - const hash_map<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm2) -{ - return !(__hm1 == __hm2); -} - -template -inline void swap(hash_map<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm1, - hash_map<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm2) -{ - __hm1.swap(__hm2); -} - -// Forward declaration of equality operator; needed for friend declaration. - -template , - class _EqualKey = std::equal_to<_Key>, - class _Alloc = std::allocator > -class hash_multimap; - -template -bool operator==(const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm1, - const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm2); - -template -class hash_multimap -{ -private: - typedef hashtable, _Key, _HashFcn, - hash_select1st, _EqualKey, _Alloc> - _Ht; - _Ht _M_ht; - -public: - typedef typename _Ht::key_type key_type; - typedef _Tp data_type; - typedef _Tp mapped_type; - typedef typename _Ht::value_type value_type; - typedef typename _Ht::hasher hasher; - typedef typename _Ht::key_equal key_equal; - - typedef typename _Ht::size_type size_type; - typedef typename _Ht::difference_type difference_type; - typedef typename _Ht::pointer pointer; - typedef typename _Ht::const_pointer const_pointer; - typedef typename _Ht::reference reference; - typedef typename _Ht::const_reference const_reference; - - typedef typename _Ht::iterator iterator; - typedef typename _Ht::const_iterator const_iterator; - - typedef typename _Ht::allocator_type allocator_type; - - hasher hash_funct() const { return _M_ht.hash_funct(); } - key_equal key_eq() const { return _M_ht.key_eq(); } - allocator_type get_allocator() const { return _M_ht.get_allocator(); } - -public: - hash_multimap() - : _M_ht(100, hasher(), key_equal(), allocator_type()) - { - } - explicit hash_multimap(size_type __n) - : _M_ht(__n, hasher(), key_equal(), allocator_type()) - { - } - hash_multimap(size_type __n, const hasher& __hf) - : _M_ht(__n, __hf, key_equal(), allocator_type()) - { - } - hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql, - const allocator_type& __a = allocator_type()) - : _M_ht(__n, __hf, __eql, __a) - { - } - - template - hash_multimap(_InputIterator __f, _InputIterator __l) - : _M_ht(100, hasher(), key_equal(), allocator_type()) - { - _M_ht.insert_equal(__f, __l); - } - template - hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n) - : _M_ht(__n, hasher(), key_equal(), allocator_type()) - { - _M_ht.insert_equal(__f, __l); - } - template - hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n, - const hasher& __hf) - : _M_ht(__n, __hf, key_equal(), allocator_type()) - { - _M_ht.insert_equal(__f, __l); - } - template - hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n, - const hasher& __hf, const key_equal& __eql, - const allocator_type& __a = allocator_type()) - : _M_ht(__n, __hf, __eql, __a) - { - _M_ht.insert_equal(__f, __l); - } - -public: - size_type size() const { return _M_ht.size(); } - size_type max_size() const { return _M_ht.max_size(); } - bool empty() const { return _M_ht.empty(); } - void swap(hash_multimap& __hs) { _M_ht.swap(__hs._M_ht); } - - friend bool operator==<>(const hash_multimap&, const hash_multimap&); - - iterator begin() { return _M_ht.begin(); } - iterator end() { return _M_ht.end(); } - const_iterator begin() const { return _M_ht.begin(); } - const_iterator end() const { return _M_ht.end(); } - -public: - iterator insert(const value_type& __obj) - { - return _M_ht.insert_equal(__obj); - } - template - void insert(_InputIterator __f, _InputIterator __l) - { - _M_ht.insert_equal(__f, __l); - } - iterator insert_noresize(const value_type& __obj) - { - return _M_ht.insert_equal_noresize(__obj); - } - - iterator find(const key_type& __key) { return _M_ht.find(__key); } - const_iterator find(const key_type& __key) const - { - return _M_ht.find(__key); - } - - size_type count(const key_type& __key) const { return _M_ht.count(__key); } - - std::pair equal_range(const key_type& __key) - { - return _M_ht.equal_range(__key); - } - std::pair equal_range( - const key_type& __key) const - { - return _M_ht.equal_range(__key); - } - - size_type erase(const key_type& __key) { return _M_ht.erase(__key); } - void erase(iterator __it) { _M_ht.erase(__it); } - void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); } - void clear() { _M_ht.clear(); } - -public: - void resize(size_type __hint) { _M_ht.resize(__hint); } - size_type bucket_count() const { return _M_ht.bucket_count(); } - size_type max_bucket_count() const { return _M_ht.max_bucket_count(); } - size_type elems_in_bucket(size_type __n) const - { - return _M_ht.elems_in_bucket(__n); - } -}; - -template -bool operator==(const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm1, - const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm2) -{ - return __hm1._M_ht == __hm2._M_ht; -} - -template -inline bool operator!=( - const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm1, - const hash_multimap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm2) -{ - return !(__hm1 == __hm2); -} - -template -inline void swap(hash_multimap<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm1, - hash_multimap<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm2) -{ - __hm1.swap(__hm2); -} - -} // namespace @KWSYS_NAMESPACE@ - -#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) -# pragma reset woff 1174 -# pragma reset woff 1375 -#endif - -#if defined(_MSC_VER) -# pragma warning(pop) -#endif - -#endif diff --git a/Utilities/KWSys/vtksys/hash_set.hxx.in b/Utilities/KWSys/vtksys/hash_set.hxx.in deleted file mode 100644 index f4a37eebd..000000000 --- a/Utilities/KWSys/vtksys/hash_set.hxx.in +++ /dev/null @@ -1,392 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -/* - * Copyright (c) 1996 - * Silicon Graphics Computer Systems, Inc. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Silicon Graphics makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - * - * Copyright (c) 1994 - * Hewlett-Packard Company - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Hewlett-Packard Company makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ -#ifndef @KWSYS_NAMESPACE@_hash_set_hxx -#define @KWSYS_NAMESPACE@_hash_set_hxx - -#include <@KWSYS_NAMESPACE@/hashtable.hxx> - -#include <@KWSYS_NAMESPACE@/hash_fun.hxx> - -#include // equal_to - -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4284) -# pragma warning(disable : 4786) -#endif - -#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) -# pragma set woff 1174 -# pragma set woff 1375 -#endif - -namespace @KWSYS_NAMESPACE@ { - -// identity is an extension: it is not part of the standard. -template -struct _Identity -{ - const _Tp& operator()(const _Tp& __x) const { return __x; } -}; - -// Forward declaration of equality operator; needed for friend declaration. - -template , - class _EqualKey = std::equal_to<_Value>, - class _Alloc = std::allocator > -class hash_set; - -template -bool operator==(const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs1, - const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs2); - -template -class hash_set -{ -private: - typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, _EqualKey, - _Alloc> - _Ht; - _Ht _M_ht; - -public: - typedef typename _Ht::key_type key_type; - typedef typename _Ht::value_type value_type; - typedef typename _Ht::hasher hasher; - typedef typename _Ht::key_equal key_equal; - - typedef typename _Ht::size_type size_type; - typedef typename _Ht::difference_type difference_type; - typedef typename _Ht::const_pointer pointer; - typedef typename _Ht::const_pointer const_pointer; - typedef typename _Ht::const_reference reference; - typedef typename _Ht::const_reference const_reference; - - typedef typename _Ht::const_iterator iterator; - typedef typename _Ht::const_iterator const_iterator; - - typedef typename _Ht::allocator_type allocator_type; - - hasher hash_funct() const { return _M_ht.hash_funct(); } - key_equal key_eq() const { return _M_ht.key_eq(); } - allocator_type get_allocator() const { return _M_ht.get_allocator(); } - -public: - hash_set() - : _M_ht(100, hasher(), key_equal(), allocator_type()) - { - } - explicit hash_set(size_type __n) - : _M_ht(__n, hasher(), key_equal(), allocator_type()) - { - } - hash_set(size_type __n, const hasher& __hf) - : _M_ht(__n, __hf, key_equal(), allocator_type()) - { - } - hash_set(size_type __n, const hasher& __hf, const key_equal& __eql, - const allocator_type& __a = allocator_type()) - : _M_ht(__n, __hf, __eql, __a) - { - } - - template - hash_set(_InputIterator __f, _InputIterator __l) - : _M_ht(100, hasher(), key_equal(), allocator_type()) - { - _M_ht.insert_unique(__f, __l); - } - template - hash_set(_InputIterator __f, _InputIterator __l, size_type __n) - : _M_ht(__n, hasher(), key_equal(), allocator_type()) - { - _M_ht.insert_unique(__f, __l); - } - template - hash_set(_InputIterator __f, _InputIterator __l, size_type __n, - const hasher& __hf) - : _M_ht(__n, __hf, key_equal(), allocator_type()) - { - _M_ht.insert_unique(__f, __l); - } - template - hash_set(_InputIterator __f, _InputIterator __l, size_type __n, - const hasher& __hf, const key_equal& __eql, - const allocator_type& __a = allocator_type()) - : _M_ht(__n, __hf, __eql, __a) - { - _M_ht.insert_unique(__f, __l); - } - -public: - size_type size() const { return _M_ht.size(); } - size_type max_size() const { return _M_ht.max_size(); } - bool empty() const { return _M_ht.empty(); } - void swap(hash_set& __hs) { _M_ht.swap(__hs._M_ht); } - - friend bool operator==<>(const hash_set&, const hash_set&); - - iterator begin() const { return _M_ht.begin(); } - iterator end() const { return _M_ht.end(); } - -public: - std::pair insert(const value_type& __obj) - { - typedef typename _Ht::iterator _Ht_iterator; - std::pair<_Ht_iterator, bool> __p = _M_ht.insert_unique(__obj); - return std::pair(__p.first, __p.second); - } - template - void insert(_InputIterator __f, _InputIterator __l) - { - _M_ht.insert_unique(__f, __l); - } - std::pair insert_noresize(const value_type& __obj) - { - typedef typename _Ht::iterator _Ht_iterator; - std::pair<_Ht_iterator, bool> __p = _M_ht.insert_unique_noresize(__obj); - return std::pair(__p.first, __p.second); - } - - iterator find(const key_type& __key) const { return _M_ht.find(__key); } - - size_type count(const key_type& __key) const { return _M_ht.count(__key); } - - std::pair equal_range(const key_type& __key) const - { - return _M_ht.equal_range(__key); - } - - size_type erase(const key_type& __key) { return _M_ht.erase(__key); } - void erase(iterator __it) { _M_ht.erase(__it); } - void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); } - void clear() { _M_ht.clear(); } - -public: - void resize(size_type __hint) { _M_ht.resize(__hint); } - size_type bucket_count() const { return _M_ht.bucket_count(); } - size_type max_bucket_count() const { return _M_ht.max_bucket_count(); } - size_type elems_in_bucket(size_type __n) const - { - return _M_ht.elems_in_bucket(__n); - } -}; - -template -bool operator==(const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs1, - const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs2) -{ - return __hs1._M_ht == __hs2._M_ht; -} - -template -inline bool operator!=( - const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs1, - const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs2) -{ - return !(__hs1 == __hs2); -} - -template -inline void swap(hash_set<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1, - hash_set<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2) -{ - __hs1.swap(__hs2); -} - -template , - class _EqualKey = std::equal_to<_Value>, - class _Alloc = std::allocator > -class hash_multiset; - -template -bool operator==(const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1, - const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2); - -template -class hash_multiset -{ -private: - typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, _EqualKey, - _Alloc> - _Ht; - _Ht _M_ht; - -public: - typedef typename _Ht::key_type key_type; - typedef typename _Ht::value_type value_type; - typedef typename _Ht::hasher hasher; - typedef typename _Ht::key_equal key_equal; - - typedef typename _Ht::size_type size_type; - typedef typename _Ht::difference_type difference_type; - typedef typename _Ht::const_pointer pointer; - typedef typename _Ht::const_pointer const_pointer; - typedef typename _Ht::const_reference reference; - typedef typename _Ht::const_reference const_reference; - - typedef typename _Ht::const_iterator iterator; - typedef typename _Ht::const_iterator const_iterator; - - typedef typename _Ht::allocator_type allocator_type; - - hasher hash_funct() const { return _M_ht.hash_funct(); } - key_equal key_eq() const { return _M_ht.key_eq(); } - allocator_type get_allocator() const { return _M_ht.get_allocator(); } - -public: - hash_multiset() - : _M_ht(100, hasher(), key_equal(), allocator_type()) - { - } - explicit hash_multiset(size_type __n) - : _M_ht(__n, hasher(), key_equal(), allocator_type()) - { - } - hash_multiset(size_type __n, const hasher& __hf) - : _M_ht(__n, __hf, key_equal(), allocator_type()) - { - } - hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql, - const allocator_type& __a = allocator_type()) - : _M_ht(__n, __hf, __eql, __a) - { - } - - template - hash_multiset(_InputIterator __f, _InputIterator __l) - : _M_ht(100, hasher(), key_equal(), allocator_type()) - { - _M_ht.insert_equal(__f, __l); - } - template - hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n) - : _M_ht(__n, hasher(), key_equal(), allocator_type()) - { - _M_ht.insert_equal(__f, __l); - } - template - hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n, - const hasher& __hf) - : _M_ht(__n, __hf, key_equal(), allocator_type()) - { - _M_ht.insert_equal(__f, __l); - } - template - hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n, - const hasher& __hf, const key_equal& __eql, - const allocator_type& __a = allocator_type()) - : _M_ht(__n, __hf, __eql, __a) - { - _M_ht.insert_equal(__f, __l); - } - -public: - size_type size() const { return _M_ht.size(); } - size_type max_size() const { return _M_ht.max_size(); } - bool empty() const { return _M_ht.empty(); } - void swap(hash_multiset& hs) { _M_ht.swap(hs._M_ht); } - - friend bool operator==<>(const hash_multiset&, const hash_multiset&); - - iterator begin() const { return _M_ht.begin(); } - iterator end() const { return _M_ht.end(); } - -public: - iterator insert(const value_type& __obj) - { - return _M_ht.insert_equal(__obj); - } - template - void insert(_InputIterator __f, _InputIterator __l) - { - _M_ht.insert_equal(__f, __l); - } - iterator insert_noresize(const value_type& __obj) - { - return _M_ht.insert_equal_noresize(__obj); - } - - iterator find(const key_type& __key) const { return _M_ht.find(__key); } - - size_type count(const key_type& __key) const { return _M_ht.count(__key); } - - std::pair equal_range(const key_type& __key) const - { - return _M_ht.equal_range(__key); - } - - size_type erase(const key_type& __key) { return _M_ht.erase(__key); } - void erase(iterator __it) { _M_ht.erase(__it); } - void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); } - void clear() { _M_ht.clear(); } - -public: - void resize(size_type __hint) { _M_ht.resize(__hint); } - size_type bucket_count() const { return _M_ht.bucket_count(); } - size_type max_bucket_count() const { return _M_ht.max_bucket_count(); } - size_type elems_in_bucket(size_type __n) const - { - return _M_ht.elems_in_bucket(__n); - } -}; - -template -bool operator==(const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1, - const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2) -{ - return __hs1._M_ht == __hs2._M_ht; -} - -template -inline bool operator!=( - const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1, - const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2) -{ - return !(__hs1 == __hs2); -} - -template -inline void swap(hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1, - hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2) -{ - __hs1.swap(__hs2); -} - -} // namespace @KWSYS_NAMESPACE@ - -#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) -# pragma reset woff 1174 -# pragma reset woff 1375 -#endif - -#if defined(_MSC_VER) -# pragma warning(pop) -#endif - -#endif diff --git a/Utilities/KWSys/vtksys/hashtable.hxx.in b/Utilities/KWSys/vtksys/hashtable.hxx.in deleted file mode 100644 index 8c4b0025f..000000000 --- a/Utilities/KWSys/vtksys/hashtable.hxx.in +++ /dev/null @@ -1,995 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -/* - * Copyright (c) 1996 - * Silicon Graphics Computer Systems, Inc. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Silicon Graphics makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - * - * Copyright (c) 1994 - * Hewlett-Packard Company - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Hewlett-Packard Company makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ -#ifdef __BORLANDC__ -# pragma warn - 8027 /* 'for' not inlined. */ -# pragma warn - 8026 /* 'exception' not inlined. */ -#endif - -#ifndef @KWSYS_NAMESPACE@_hashtable_hxx -# define @KWSYS_NAMESPACE@_hashtable_hxx - -# include <@KWSYS_NAMESPACE@/Configure.hxx> - -# include // lower_bound -# include // iterator_traits -# include // allocator -# include // size_t -# include // pair -# include // vector - -# if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4284) -# pragma warning(disable : 4786) -# pragma warning(disable : 4512) /* no assignment operator for class */ -# endif -# if defined(__sgi) && !defined(__GNUC__) -# pragma set woff 3970 /* pointer to int conversion */ 3321 3968 -# endif - -// In C++11, clang will warn about using dynamic exception specifications -// as they are deprecated. But as this class is trying to faithfully -// mimic unordered_set and unordered_map, we want to keep the 'throw()' -// decorations below. So we suppress the warning. -# if defined(__clang__) && defined(__has_warning) -# if __has_warning("-Wdeprecated") -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wdeprecated" -# endif -# endif - -namespace @KWSYS_NAMESPACE@ { - -template -struct _Hashtable_node -{ - _Hashtable_node* _M_next; - _Val _M_val; - void public_method_to_quiet_warning_about_all_methods_private(); - -private: - void operator=(_Hashtable_node<_Val> const&) = delete; -}; - -template > -class hashtable; - -template -struct _Hashtable_iterator; - -template -struct _Hashtable_const_iterator; - -template -struct _Hashtable_iterator -{ - typedef hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc> - _Hashtable; - typedef _Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, - _Alloc> - iterator; - typedef _Hashtable_const_iterator<_Val, _Key, _HashFcn, _ExtractKey, - _EqualKey, _Alloc> - const_iterator; - typedef _Hashtable_node<_Val> _Node; - - typedef std::forward_iterator_tag iterator_category; - typedef _Val value_type; - typedef ptrdiff_t difference_type; - typedef size_t size_type; - typedef _Val& reference; - typedef _Val* pointer; - - _Node* _M_cur; - _Hashtable* _M_ht; - - _Hashtable_iterator(_Node* __n, _Hashtable* __tab) - : _M_cur(__n) - , _M_ht(__tab) - { - } - _Hashtable_iterator() {} - reference operator*() const { return _M_cur->_M_val; } - pointer operator->() const { return &(operator*()); } - iterator& operator++(); - iterator operator++(int); - bool operator==(const iterator& __it) const { return _M_cur == __it._M_cur; } - bool operator!=(const iterator& __it) const { return _M_cur != __it._M_cur; } -}; - -template -struct _Hashtable_const_iterator -{ - typedef hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc> - _Hashtable; - typedef _Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, - _Alloc> - iterator; - typedef _Hashtable_const_iterator<_Val, _Key, _HashFcn, _ExtractKey, - _EqualKey, _Alloc> - const_iterator; - typedef _Hashtable_node<_Val> _Node; - - typedef std::forward_iterator_tag iterator_category; - typedef _Val value_type; - typedef ptrdiff_t difference_type; - typedef size_t size_type; - typedef const _Val& reference; - typedef const _Val* pointer; - - const _Node* _M_cur; - const _Hashtable* _M_ht; - - _Hashtable_const_iterator(const _Node* __n, const _Hashtable* __tab) - : _M_cur(__n) - , _M_ht(__tab) - { - } - _Hashtable_const_iterator() {} - _Hashtable_const_iterator(const iterator& __it) - : _M_cur(__it._M_cur) - , _M_ht(__it._M_ht) - { - } - reference operator*() const { return _M_cur->_M_val; } - pointer operator->() const { return &(operator*()); } - const_iterator& operator++(); - const_iterator operator++(int); - bool operator==(const const_iterator& __it) const - { - return _M_cur == __it._M_cur; - } - bool operator!=(const const_iterator& __it) const - { - return _M_cur != __it._M_cur; - } -}; - -// Note: assumes long is at least 32 bits. -enum -{ - _stl_num_primes = 31 -}; - -// create a function with a static local to that function that returns -// the static -static inline const unsigned long* get_stl_prime_list() -{ - - static const unsigned long _stl_prime_list[_stl_num_primes] = { - 5ul, 11ul, 23ul, 53ul, 97ul, - 193ul, 389ul, 769ul, 1543ul, 3079ul, - 6151ul, 12289ul, 24593ul, 49157ul, 98317ul, - 196613ul, 393241ul, 786433ul, 1572869ul, 3145739ul, - 6291469ul, 12582917ul, 25165843ul, 50331653ul, 100663319ul, - 201326611ul, 402653189ul, 805306457ul, 1610612741ul, 3221225473ul, - 4294967291ul - }; - - return &_stl_prime_list[0]; -} - -static inline size_t _stl_next_prime(size_t __n) -{ - const unsigned long* __first = get_stl_prime_list(); - const unsigned long* __last = get_stl_prime_list() + (int)_stl_num_primes; - const unsigned long* pos = std::lower_bound(__first, __last, __n); - return pos == __last ? *(__last - 1) : *pos; -} - -// Forward declaration of operator==. - -template -class hashtable; - -template -bool operator==(const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht1, - const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht2); - -// Hashtables handle allocators a bit differently than other containers -// do. If we're using standard-conforming allocators, then a hashtable -// unconditionally has a member variable to hold its allocator, even if -// it so happens that all instances of the allocator type are identical. -// This is because, for hashtables, this extra storage is negligible. -// Additionally, a base class wouldn't serve any other purposes; it -// wouldn't, for example, simplify the exception-handling code. - -template -class hashtable -{ -public: - typedef _Key key_type; - typedef _Val value_type; - typedef _HashFcn hasher; - typedef _EqualKey key_equal; - - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - hasher hash_funct() const { return _M_hash; } - key_equal key_eq() const { return _M_equals; } - -private: - typedef _Hashtable_node<_Val> _Node; - -public: - typedef typename _Alloc::template rebind<_Val>::other allocator_type; - allocator_type get_allocator() const { return _M_node_allocator; } - -private: - typedef - typename _Alloc::template rebind<_Node>::other _M_node_allocator_type; - typedef - typename _Alloc::template rebind<_Node*>::other _M_node_ptr_allocator_type; - typedef std::vector<_Node*, _M_node_ptr_allocator_type> _M_buckets_type; - -private: - _M_node_allocator_type _M_node_allocator; - hasher _M_hash; - key_equal _M_equals; - _ExtractKey _M_get_key; - _M_buckets_type _M_buckets; - size_type _M_num_elements; - - _Node* _M_get_node() { return _M_node_allocator.allocate(1); } - void _M_put_node(_Node* __p) { _M_node_allocator.deallocate(__p, 1); } - -public: - typedef _Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, - _Alloc> - iterator; - typedef _Hashtable_const_iterator<_Val, _Key, _HashFcn, _ExtractKey, - _EqualKey, _Alloc> - const_iterator; - - friend struct _Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, - _EqualKey, _Alloc>; - friend struct _Hashtable_const_iterator<_Val, _Key, _HashFcn, _ExtractKey, - _EqualKey, _Alloc>; - -public: - hashtable(size_type __n, const _HashFcn& __hf, const _EqualKey& __eql, - const _ExtractKey& __ext, - const allocator_type& __a = allocator_type()) - : _M_node_allocator(__a) - , _M_hash(__hf) - , _M_equals(__eql) - , _M_get_key(__ext) - , _M_buckets(__a) - , _M_num_elements(0) - { - _M_initialize_buckets(__n); - } - - hashtable(size_type __n, const _HashFcn& __hf, const _EqualKey& __eql, - const allocator_type& __a = allocator_type()) - : _M_node_allocator(__a) - , _M_hash(__hf) - , _M_equals(__eql) - , _M_get_key(_ExtractKey()) - , _M_buckets(__a) - , _M_num_elements(0) - { - _M_initialize_buckets(__n); - } - - hashtable(const hashtable& __ht) - : _M_node_allocator(__ht.get_allocator()) - , _M_hash(__ht._M_hash) - , _M_equals(__ht._M_equals) - , _M_get_key(__ht._M_get_key) - , _M_buckets(__ht.get_allocator()) - , _M_num_elements(0) - { - _M_copy_from(__ht); - } - - hashtable& operator=(const hashtable& __ht) - { - if (&__ht != this) { - clear(); - _M_hash = __ht._M_hash; - _M_equals = __ht._M_equals; - _M_get_key = __ht._M_get_key; - _M_copy_from(__ht); - } - return *this; - } - - ~hashtable() { clear(); } - - size_type size() const { return _M_num_elements; } - size_type max_size() const { return size_type(-1); } - bool empty() const { return size() == 0; } - - void swap(hashtable& __ht) - { - std::swap(_M_hash, __ht._M_hash); - std::swap(_M_equals, __ht._M_equals); - std::swap(_M_get_key, __ht._M_get_key); - _M_buckets.swap(__ht._M_buckets); - std::swap(_M_num_elements, __ht._M_num_elements); - } - - iterator begin() - { - for (size_type __n = 0; __n < _M_buckets.size(); ++__n) - if (_M_buckets[__n]) - return iterator(_M_buckets[__n], this); - return end(); - } - - iterator end() { return iterator(nullptr, this); } - - const_iterator begin() const - { - for (size_type __n = 0; __n < _M_buckets.size(); ++__n) - if (_M_buckets[__n]) - return const_iterator(_M_buckets[__n], this); - return end(); - } - - const_iterator end() const { return const_iterator(nullptr, this); } - - friend bool operator==<>(const hashtable&, const hashtable&); - -public: - size_type bucket_count() const { return _M_buckets.size(); } - - size_type max_bucket_count() const - { - return get_stl_prime_list()[(int)_stl_num_primes - 1]; - } - - size_type elems_in_bucket(size_type __bucket) const - { - size_type __result = 0; - for (_Node* __cur = _M_buckets[__bucket]; __cur; __cur = __cur->_M_next) - __result += 1; - return __result; - } - - std::pair insert_unique(const value_type& __obj) - { - resize(_M_num_elements + 1); - return insert_unique_noresize(__obj); - } - - iterator insert_equal(const value_type& __obj) - { - resize(_M_num_elements + 1); - return insert_equal_noresize(__obj); - } - - std::pair insert_unique_noresize(const value_type& __obj); - iterator insert_equal_noresize(const value_type& __obj); - - template - void insert_unique(_InputIterator __f, _InputIterator __l) - { - insert_unique( - __f, __l, - typename std::iterator_traits<_InputIterator>::iterator_category()); - } - - template - void insert_equal(_InputIterator __f, _InputIterator __l) - { - insert_equal( - __f, __l, - typename std::iterator_traits<_InputIterator>::iterator_category()); - } - - template - void insert_unique(_InputIterator __f, _InputIterator __l, - std::input_iterator_tag) - { - for (; __f != __l; ++__f) - insert_unique(*__f); - } - - template - void insert_equal(_InputIterator __f, _InputIterator __l, - std::input_iterator_tag) - { - for (; __f != __l; ++__f) - insert_equal(*__f); - } - - template - void insert_unique(_ForwardIterator __f, _ForwardIterator __l, - std::forward_iterator_tag) - { - size_type __n = 0; - std::distance(__f, __l, __n); - resize(_M_num_elements + __n); - for (; __n > 0; --__n, ++__f) - insert_unique_noresize(*__f); - } - - template - void insert_equal(_ForwardIterator __f, _ForwardIterator __l, - std::forward_iterator_tag) - { - size_type __n = 0; - std::distance(__f, __l, __n); - resize(_M_num_elements + __n); - for (; __n > 0; --__n, ++__f) - insert_equal_noresize(*__f); - } - - reference find_or_insert(const value_type& __obj); - - iterator find(const key_type& __key) - { - size_type __n = _M_bkt_num_key(__key); - _Node* __first; - for (__first = _M_buckets[__n]; - __first && !_M_equals(_M_get_key(__first->_M_val), __key); - __first = __first->_M_next) { - } - return iterator(__first, this); - } - - const_iterator find(const key_type& __key) const - { - size_type __n = _M_bkt_num_key(__key); - const _Node* __first; - for (__first = _M_buckets[__n]; - __first && !_M_equals(_M_get_key(__first->_M_val), __key); - __first = __first->_M_next) { - } - return const_iterator(__first, this); - } - - size_type count(const key_type& __key) const - { - const size_type __n = _M_bkt_num_key(__key); - size_type __result = 0; - - for (const _Node* __cur = _M_buckets[__n]; __cur; __cur = __cur->_M_next) - if (_M_equals(_M_get_key(__cur->_M_val), __key)) - ++__result; - return __result; - } - - std::pair equal_range(const key_type& __key); - - std::pair equal_range( - const key_type& __key) const; - - size_type erase(const key_type& __key); - void erase(const iterator& __it); - void erase(iterator __first, iterator __last); - - void erase(const const_iterator& __it); - void erase(const_iterator __first, const_iterator __last); - - void resize(size_type __num_elements_hint); - void clear(); - -private: - size_type _M_next_size(size_type __n) const { return _stl_next_prime(__n); } - - void _M_initialize_buckets(size_type __n) - { - const size_type __n_buckets = _M_next_size(__n); - _M_buckets.reserve(__n_buckets); - _M_buckets.insert(_M_buckets.end(), __n_buckets, (_Node*)nullptr); - _M_num_elements = 0; - } - - size_type _M_bkt_num_key(const key_type& __key) const - { - return _M_bkt_num_key(__key, _M_buckets.size()); - } - - size_type _M_bkt_num(const value_type& __obj) const - { - return _M_bkt_num_key(_M_get_key(__obj)); - } - - size_type _M_bkt_num_key(const key_type& __key, size_t __n) const - { - return _M_hash(__key) % __n; - } - - size_type _M_bkt_num(const value_type& __obj, size_t __n) const - { - return _M_bkt_num_key(_M_get_key(__obj), __n); - } - - void construct(_Val* p, const _Val& v) { new (p) _Val(v); } - void destroy(_Val* p) - { - (void)p; - p->~_Val(); - } - - _Node* _M_new_node(const value_type& __obj) - { - _Node* __n = _M_get_node(); - __n->_M_next = nullptr; - try { - construct(&__n->_M_val, __obj); - return __n; - } catch (...) { - _M_put_node(__n); - throw; - } - } - - void _M_delete_node(_Node* __n) - { - destroy(&__n->_M_val); - _M_put_node(__n); - } - - void _M_erase_bucket(const size_type __n, _Node* __first, _Node* __last); - void _M_erase_bucket(const size_type __n, _Node* __last); - - void _M_copy_from(const hashtable& __ht); -}; - -template -_Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>& -_Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++() -{ - const _Node* __old = _M_cur; - _M_cur = _M_cur->_M_next; - if (!_M_cur) { - size_type __bucket = _M_ht->_M_bkt_num(__old->_M_val); - while (!_M_cur && ++__bucket < _M_ht->_M_buckets.size()) - _M_cur = _M_ht->_M_buckets[__bucket]; - } - return *this; -} - -template -inline _Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All> -_Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++(int) -{ - iterator __tmp = *this; - ++*this; - return __tmp; -} - -template -_Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>& -_Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++() -{ - const _Node* __old = _M_cur; - _M_cur = _M_cur->_M_next; - if (!_M_cur) { - size_type __bucket = _M_ht->_M_bkt_num(__old->_M_val); - while (!_M_cur && ++__bucket < _M_ht->_M_buckets.size()) - _M_cur = _M_ht->_M_buckets[__bucket]; - } - return *this; -} - -template -inline _Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All> -_Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++(int) -{ - const_iterator __tmp = *this; - ++*this; - return __tmp; -} - -template -bool operator==(const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht1, - const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht2) -{ - typedef typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_Node _Node; - if (__ht1._M_buckets.size() != __ht2._M_buckets.size()) - return false; - for (int __n = 0; __n < __ht1._M_buckets.size(); ++__n) { - _Node* __cur1 = __ht1._M_buckets[__n]; - _Node* __cur2 = __ht2._M_buckets[__n]; - for (; __cur1 && __cur2 && __cur1->_M_val == __cur2->_M_val; - __cur1 = __cur1->_M_next, __cur2 = __cur2->_M_next) { - } - if (__cur1 || __cur2) - return false; - } - return true; -} - -template -inline bool operator!=(const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht1, - const hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>& __ht2) -{ - return !(__ht1 == __ht2); -} - -template -inline void swap(hashtable<_Val, _Key, _HF, _Extract, _EqKey, _All>& __ht1, - hashtable<_Val, _Key, _HF, _Extract, _EqKey, _All>& __ht2) -{ - __ht1.swap(__ht2); -} - -template -std::pair::iterator, bool> -hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::insert_unique_noresize( - const value_type& __obj) -{ - const size_type __n = _M_bkt_num(__obj); - _Node* __first = _M_buckets[__n]; - - for (_Node* __cur = __first; __cur; __cur = __cur->_M_next) - if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj))) - return std::pair(iterator(__cur, this), false); - - _Node* __tmp = _M_new_node(__obj); - __tmp->_M_next = __first; - _M_buckets[__n] = __tmp; - ++_M_num_elements; - return std::pair(iterator(__tmp, this), true); -} - -template -typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::iterator -hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::insert_equal_noresize( - const value_type& __obj) -{ - const size_type __n = _M_bkt_num(__obj); - _Node* __first = _M_buckets[__n]; - - for (_Node* __cur = __first; __cur; __cur = __cur->_M_next) - if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj))) { - _Node* __tmp = _M_new_node(__obj); - __tmp->_M_next = __cur->_M_next; - __cur->_M_next = __tmp; - ++_M_num_elements; - return iterator(__tmp, this); - } - - _Node* __tmp = _M_new_node(__obj); - __tmp->_M_next = __first; - _M_buckets[__n] = __tmp; - ++_M_num_elements; - return iterator(__tmp, this); -} - -template -typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::reference -hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::find_or_insert( - const value_type& __obj) -{ - resize(_M_num_elements + 1); - - size_type __n = _M_bkt_num(__obj); - _Node* __first = _M_buckets[__n]; - - for (_Node* __cur = __first; __cur; __cur = __cur->_M_next) - if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj))) - return __cur->_M_val; - - _Node* __tmp = _M_new_node(__obj); - __tmp->_M_next = __first; - _M_buckets[__n] = __tmp; - ++_M_num_elements; - return __tmp->_M_val; -} - -template -std::pair::iterator, - typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::iterator> -hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::equal_range(const key_type& __key) -{ - typedef std::pair _Pii; - const size_type __n = _M_bkt_num_key(__key); - - for (_Node* __first = _M_buckets[__n]; __first; __first = __first->_M_next) - if (_M_equals(_M_get_key(__first->_M_val), __key)) { - for (_Node* __cur = __first->_M_next; __cur; __cur = __cur->_M_next) - if (!_M_equals(_M_get_key(__cur->_M_val), __key)) - return _Pii(iterator(__first, this), iterator(__cur, this)); - for (size_type __m = __n + 1; __m < _M_buckets.size(); ++__m) - if (_M_buckets[__m]) - return _Pii(iterator(__first, this), - iterator(_M_buckets[__m], this)); - return _Pii(iterator(__first, this), end()); - } - return _Pii(end(), end()); -} - -template -std::pair::const_iterator, - typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::const_iterator> -hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::equal_range( - const key_type& __key) const -{ - typedef std::pair _Pii; - const size_type __n = _M_bkt_num_key(__key); - - for (const _Node* __first = _M_buckets[__n]; __first; - __first = __first->_M_next) { - if (_M_equals(_M_get_key(__first->_M_val), __key)) { - for (const _Node* __cur = __first->_M_next; __cur; - __cur = __cur->_M_next) - if (!_M_equals(_M_get_key(__cur->_M_val), __key)) - return _Pii(const_iterator(__first, this), - const_iterator(__cur, this)); - for (size_type __m = __n + 1; __m < _M_buckets.size(); ++__m) - if (_M_buckets[__m]) - return _Pii(const_iterator(__first, this), - const_iterator(_M_buckets[__m], this)); - return _Pii(const_iterator(__first, this), end()); - } - } - return _Pii(end(), end()); -} - -template -typename hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::size_type -hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase(const key_type& __key) -{ - const size_type __n = _M_bkt_num_key(__key); - _Node* __first = _M_buckets[__n]; - size_type __erased = 0; - - if (__first) { - _Node* __cur = __first; - _Node* __next = __cur->_M_next; - while (__next) { - if (_M_equals(_M_get_key(__next->_M_val), __key)) { - __cur->_M_next = __next->_M_next; - _M_delete_node(__next); - __next = __cur->_M_next; - ++__erased; - --_M_num_elements; - } else { - __cur = __next; - __next = __cur->_M_next; - } - } - if (_M_equals(_M_get_key(__first->_M_val), __key)) { - _M_buckets[__n] = __first->_M_next; - _M_delete_node(__first); - ++__erased; - --_M_num_elements; - } - } - return __erased; -} - -template -void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase(const iterator& __it) -{ - _Node* __p = __it._M_cur; - if (__p) { - const size_type __n = _M_bkt_num(__p->_M_val); - _Node* __cur = _M_buckets[__n]; - - if (__cur == __p) { - _M_buckets[__n] = __cur->_M_next; - _M_delete_node(__cur); - --_M_num_elements; - } else { - _Node* __next = __cur->_M_next; - while (__next) { - if (__next == __p) { - __cur->_M_next = __next->_M_next; - _M_delete_node(__next); - --_M_num_elements; - break; - } else { - __cur = __next; - __next = __cur->_M_next; - } - } - } - } -} - -template -void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase(iterator __first, - iterator __last) -{ - size_type __f_bucket = - __first._M_cur ? _M_bkt_num(__first._M_cur->_M_val) : _M_buckets.size(); - size_type __l_bucket = - __last._M_cur ? _M_bkt_num(__last._M_cur->_M_val) : _M_buckets.size(); - - if (__first._M_cur == __last._M_cur) - return; - else if (__f_bucket == __l_bucket) - _M_erase_bucket(__f_bucket, __first._M_cur, __last._M_cur); - else { - _M_erase_bucket(__f_bucket, __first._M_cur, nullptr); - for (size_type __n = __f_bucket + 1; __n < __l_bucket; ++__n) - _M_erase_bucket(__n, nullptr); - if (__l_bucket != _M_buckets.size()) - _M_erase_bucket(__l_bucket, __last._M_cur); - } -} - -template -inline void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase( - const_iterator __first, const_iterator __last) -{ - erase(iterator(const_cast<_Node*>(__first._M_cur), - const_cast(__first._M_ht)), - iterator(const_cast<_Node*>(__last._M_cur), - const_cast(__last._M_ht))); -} - -template -inline void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::erase( - const const_iterator& __it) -{ - erase(iterator(const_cast<_Node*>(__it._M_cur), - const_cast(__it._M_ht))); -} - -template -void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::resize( - size_type __num_elements_hint) -{ - const size_type __old_n = _M_buckets.size(); - if (__num_elements_hint > __old_n) { - const size_type __n = _M_next_size(__num_elements_hint); - if (__n > __old_n) { - _M_buckets_type __tmp(__n, (_Node*)(nullptr), - _M_buckets.get_allocator()); - try { - for (size_type __bucket = 0; __bucket < __old_n; ++__bucket) { - _Node* __first = _M_buckets[__bucket]; - while (__first) { - size_type __new_bucket = _M_bkt_num(__first->_M_val, __n); - _M_buckets[__bucket] = __first->_M_next; - __first->_M_next = __tmp[__new_bucket]; - __tmp[__new_bucket] = __first; - __first = _M_buckets[__bucket]; - } - } - _M_buckets.swap(__tmp); - } catch (...) { - for (size_type __bucket = 0; __bucket < __tmp.size(); ++__bucket) { - while (__tmp[__bucket]) { - _Node* __next = __tmp[__bucket]->_M_next; - _M_delete_node(__tmp[__bucket]); - __tmp[__bucket] = __next; - } - } - throw; - } - } - } -} - -template -void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_M_erase_bucket( - const size_type __n, _Node* __first, _Node* __last) -{ - _Node* __cur = _M_buckets[__n]; - if (__cur == __first) - _M_erase_bucket(__n, __last); - else { - _Node* __next; - for (__next = __cur->_M_next; __next != __first; - __cur = __next, __next = __cur->_M_next) - ; - while (__next != __last) { - __cur->_M_next = __next->_M_next; - _M_delete_node(__next); - __next = __cur->_M_next; - --_M_num_elements; - } - } -} - -template -void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_M_erase_bucket( - const size_type __n, _Node* __last) -{ - _Node* __cur = _M_buckets[__n]; - while (__cur != __last) { - _Node* __next = __cur->_M_next; - _M_delete_node(__cur); - __cur = __next; - _M_buckets[__n] = __cur; - --_M_num_elements; - } -} - -template -void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::clear() -{ - for (size_type __i = 0; __i < _M_buckets.size(); ++__i) { - _Node* __cur = _M_buckets[__i]; - while (__cur != nullptr) { - _Node* __next = __cur->_M_next; - _M_delete_node(__cur); - __cur = __next; - } - _M_buckets[__i] = nullptr; - } - _M_num_elements = 0; -} - -template -void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_M_copy_from( - const hashtable& __ht) -{ - _M_buckets.clear(); - _M_buckets.reserve(__ht._M_buckets.size()); - _M_buckets.insert(_M_buckets.end(), __ht._M_buckets.size(), (_Node*)nullptr); - try { - for (size_type __i = 0; __i < __ht._M_buckets.size(); ++__i) { - const _Node* __cur = __ht._M_buckets[__i]; - if (__cur) { - _Node* __copy = _M_new_node(__cur->_M_val); - _M_buckets[__i] = __copy; - - for (_Node* __next = __cur->_M_next; __next; - __cur = __next, __next = __cur->_M_next) { - __copy->_M_next = _M_new_node(__next->_M_val); - __copy = __copy->_M_next; - } - } - } - _M_num_elements = __ht._M_num_elements; - } catch (...) { - clear(); - throw; - } -} - -} // namespace @KWSYS_NAMESPACE@ - -// Undo warning suppression. -# if defined(__clang__) && defined(__has_warning) -# if __has_warning("-Wdeprecated") -# pragma clang diagnostic pop -# endif -# endif - -# if defined(_MSC_VER) -# pragma warning(pop) -# endif - -#endif diff --git a/Utilities/KWSys/vtksys/kwsysPlatformTestsC.c b/Utilities/KWSys/vtksys/kwsysPlatformTestsC.c index b0cf7ad3b..d44f7eb9c 100644 --- a/Utilities/KWSys/vtksys/kwsysPlatformTestsC.c +++ b/Utilities/KWSys/vtksys/kwsysPlatformTestsC.c @@ -69,40 +69,3 @@ int KWSYS_PLATFORM_TEST_C_MAIN() return clock_gettime(CLOCK_MONOTONIC, &ts); } #endif - -#ifdef TEST_KWSYS_C_TYPE_MACROS -char* info_macros = -# if defined(__SIZEOF_SHORT__) - "INFO:macro[__SIZEOF_SHORT__]\n" -# endif -# if defined(__SIZEOF_INT__) - "INFO:macro[__SIZEOF_INT__]\n" -# endif -# if defined(__SIZEOF_LONG__) - "INFO:macro[__SIZEOF_LONG__]\n" -# endif -# if defined(__SIZEOF_LONG_LONG__) - "INFO:macro[__SIZEOF_LONG_LONG__]\n" -# endif -# if defined(__SHORT_MAX__) - "INFO:macro[__SHORT_MAX__]\n" -# endif -# if defined(__INT_MAX__) - "INFO:macro[__INT_MAX__]\n" -# endif -# if defined(__LONG_MAX__) - "INFO:macro[__LONG_MAX__]\n" -# endif -# if defined(__LONG_LONG_MAX__) - "INFO:macro[__LONG_LONG_MAX__]\n" -# endif - ""; - -int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv) -{ - int require = 0; - require += info_macros[argc]; - (void)argv; - return require; -} -#endif diff --git a/Utilities/KWSys/vtksys/kwsysPlatformTestsCXX.cxx b/Utilities/KWSys/vtksys/kwsysPlatformTestsCXX.cxx index cfd5666f3..0bfa20ee1 100644 --- a/Utilities/KWSys/vtksys/kwsysPlatformTestsCXX.cxx +++ b/Utilities/KWSys/vtksys/kwsysPlatformTestsCXX.cxx @@ -1,36 +1,5 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#ifdef TEST_KWSYS_CXX_HAS_CSTDIO -# include -int main() -{ - return 0; -} -#endif - -#ifdef TEST_KWSYS_CXX_HAS_LONG_LONG -long long f(long long n) -{ - return n; -} -int main() -{ - long long n = 0; - return static_cast(f(n)); -} -#endif - -#ifdef TEST_KWSYS_CXX_HAS___INT64 -__int64 f(__int64 n) -{ - return n; -} -int main() -{ - __int64 n = 0; - return static_cast(f(n)); -} -#endif #ifdef TEST_KWSYS_CXX_STAT_HAS_ST_MTIM # include @@ -60,82 +29,6 @@ int main() } #endif -#ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64 -void function(long**) -{ -} -int main() -{ - __int64** p = 0; - function(p); - return 0; -} -#endif - -#ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64 -void function(long long**) -{ -} -int main() -{ - __int64** p = 0; - function(p); - return 0; -} -#endif - -#ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG -# include -int test_istream(std::istream& is, long long& x) -{ - return (is >> x) ? 1 : 0; -} -int main() -{ - long long x = 0; - return test_istream(std::cin, x); -} -#endif - -#ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG -# include -int test_ostream(std::ostream& os, long long x) -{ - return (os << x) ? 1 : 0; -} -int main() -{ - long long x = 0; - return test_ostream(std::cout, x); -} -#endif - -#ifdef TEST_KWSYS_IOS_HAS_ISTREAM___INT64 -# include -int test_istream(std::istream& is, __int64& x) -{ - return (is >> x) ? 1 : 0; -} -int main() -{ - __int64 x = 0; - return test_istream(std::cin, x); -} -#endif - -#ifdef TEST_KWSYS_IOS_HAS_OSTREAM___INT64 -# include -int test_ostream(std::ostream& os, __int64 x) -{ - return (os << x) ? 1 : 0; -} -int main() -{ - __int64 x = 0; - return test_ostream(std::cout, x); -} -#endif - #ifdef TEST_KWSYS_CXX_HAS_SETENV # include int main() @@ -184,33 +77,6 @@ int main() } #endif -#ifdef TEST_KWSYS_CXX_HAS_ATOLL -# include -int main() -{ - const char* str = "1024"; - return static_cast(atoll(str)); -} -#endif - -#ifdef TEST_KWSYS_CXX_HAS_ATOL -# include -int main() -{ - const char* str = "1024"; - return static_cast(atol(str)); -} -#endif - -#ifdef TEST_KWSYS_CXX_HAS__ATOI64 -# include -int main() -{ - const char* str = "1024"; - return static_cast(_atoi64(str)); -} -#endif - #ifdef TEST_KWSYS_CXX_HAS_UTIMES # include int main() @@ -288,33 +154,6 @@ int main() } #endif -#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM -int main() -{ - int a = 1; - __asm { - xor EBX, EBX; - mov a, EBX; - } - - return a; -} -#endif - -#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM_CPUID -int main() -{ - int a = 0; - __asm { - xor EAX, EAX; - cpuid; - mov a, EAX; - } - - return a; -} -#endif - #ifdef TEST_KWSYS_STL_HAS_WSTRING # include void f(std::wstring*) diff --git a/Utilities/KWSys/vtksys/testCommandLineArguments.cxx b/Utilities/KWSys/vtksys/testCommandLineArguments.cxx index 79ebe1a21..078675159 100644 --- a/Utilities/KWSys/vtksys/testCommandLineArguments.cxx +++ b/Utilities/KWSys/vtksys/testCommandLineArguments.cxx @@ -12,8 +12,8 @@ #include #include -#include /* size_t */ -#include /* strcmp */ +#include /* size_t */ +#include /* strcmp */ static void* random_ptr = reinterpret_cast(0x123); diff --git a/Utilities/KWSys/vtksys/testCommandLineArguments1.cxx b/Utilities/KWSys/vtksys/testCommandLineArguments1.cxx index cbc30024b..2f6b73578 100644 --- a/Utilities/KWSys/vtksys/testCommandLineArguments1.cxx +++ b/Utilities/KWSys/vtksys/testCommandLineArguments1.cxx @@ -12,8 +12,8 @@ #include #include -#include /* assert */ -#include /* strcmp */ +#include /* assert */ +#include /* strcmp */ int testCommandLineArguments1(int argc, char* argv[]) { @@ -51,9 +51,7 @@ int testCommandLineArguments1(int argc, char* argv[]) std::cout << "Value of N: " << n << std::endl; std::cout << "Value of M: " << m << std::endl; std::cout << "Value of P: " << p << std::endl; - if (m) { - delete[] m; - } + delete[] m; char** newArgv = nullptr; int newArgc = 0; diff --git a/Utilities/KWSys/vtksys/testDirectory.cxx b/Utilities/KWSys/vtksys/testDirectory.cxx index b1ab0c872..eb3ca3254 100644 --- a/Utilities/KWSys/vtksys/testDirectory.cxx +++ b/Utilities/KWSys/vtksys/testDirectory.cxx @@ -57,7 +57,11 @@ int _doLongPathTest() Directory testdir; // Set res to failure if the directory doesn't load - res += !testdir.Load(testdirpath); + std::string errorMessage = ""; + res += !testdir.Load(testdirpath, &errorMessage); + if (errorMessage != "") { + std::cerr << "Failed to list directory: " << errorMessage << std::endl; + } // Increment res failure if the directory appears empty res += testdir.GetNumberOfFiles() == 0; // Increment res failures if the path has changed from @@ -73,6 +77,34 @@ int _doLongPathTest() return res; } +int _nonExistentDirectoryTest() +{ + using namespace kwsys; + int res = 0; + std::string testdirpath(TEST_SYSTEMTOOLS_BINARY_DIR + "/directory_testing/doesnt_exist/"); + std::string errorMessage; + Directory testdir; + + errorMessage = "foo"; + // Increment res failure if directory lists + res += testdir.Load(testdirpath, &errorMessage); +#if !defined(_WIN32) || defined(__CYGWIN__) + // Increment res failure if errorMessage is unmodified + res += (errorMessage == "foo"); +#endif + + errorMessage = "foo"; + // Increment res failure if directory has files + res += (testdir.GetNumberOfFilesInDirectory(testdirpath, &errorMessage) > 0); +#if !defined(_WIN32) || defined(__CYGWIN__) + // Increment res failure if errorMessage is unmodified + res += (errorMessage == "foo"); +#endif + + return res; +} + int _copyDirectoryTest() { using namespace kwsys; @@ -106,5 +138,6 @@ int _copyDirectoryTest() int testDirectory(int, char* []) { - return _doLongPathTest() + _copyDirectoryTest(); + return _doLongPathTest() + _nonExistentDirectoryTest() + + _copyDirectoryTest(); } diff --git a/Utilities/KWSys/vtksys/testDynload.c b/Utilities/KWSys/vtksys/testDynload.c index c49f747df..33a431e9d 100644 --- a/Utilities/KWSys/vtksys/testDynload.c +++ b/Utilities/KWSys/vtksys/testDynload.c @@ -8,6 +8,6 @@ DL_EXPORT int TestDynamicLoaderData = 0; -DL_EXPORT void TestDynamicLoaderSymbolPointer() +DL_EXPORT void TestDynamicLoaderSymbolPointer(void) { } diff --git a/Utilities/KWSys/vtksys/testEncoding.cxx b/Utilities/KWSys/vtksys/testEncoding.cxx index d672aede8..ee93e8d8d 100644 --- a/Utilities/KWSys/vtksys/testEncoding.cxx +++ b/Utilities/KWSys/vtksys/testEncoding.cxx @@ -10,10 +10,10 @@ #include KWSYS_HEADER(Encoding.h) #include +#include +#include +#include #include -#include -#include -#include // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. @@ -59,7 +59,7 @@ static int testHelloWorldEncoding() std::string str2 = kwsys::Encoding::ToNarrow(wstr); wchar_t* c_wstr = kwsysEncoding_DupToWide(str.c_str()); char* c_str2 = kwsysEncoding_DupToNarrow(c_wstr); - if (!wstr.empty() && (str != str2 || strcmp(c_str2, str.c_str()))) { + if (!wstr.empty() && (str != str2 || strcmp(c_str2, str.c_str()) != 0)) { std::cout << "converted string was different: " << str2 << std::endl; std::cout << "converted string was different: " << c_str2 << std::endl; ret++; diff --git a/Utilities/KWSys/vtksys/testFStream.cxx b/Utilities/KWSys/vtksys/testFStream.cxx index 5009e9887..3325e2046 100644 --- a/Utilities/KWSys/vtksys/testFStream.cxx +++ b/Utilities/KWSys/vtksys/testFStream.cxx @@ -7,10 +7,7 @@ #endif #include KWSYS_HEADER(FStream.hxx) -#include -#ifdef __BORLANDC__ -# include /* memcmp */ -#endif +#include // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. @@ -102,12 +99,50 @@ static int testBOM() return 0; } +static int testBOMIO() +{ + // test various encodings in binary mode + for (int i = 0; i < num_test_files; i++) { + kwsys::fstream f("bomio.txt", + kwsys::fstream::in | kwsys::fstream::out | + kwsys::fstream::binary | kwsys::fstream::trunc); + f.write(reinterpret_cast(expected_bom_data[i] + 1), + *expected_bom_data[i]); + f.write(reinterpret_cast(file_data[i] + 1), file_data[i][0]); + if (!f.good()) { + std::cout << "Unable to write data " << i << std::endl; + return 1; + } + f.seekp(0); + + kwsys::FStream::BOM bom = kwsys::FStream::ReadBOM(f); + if (bom != expected_bom[i]) { + std::cout << "Unexpected BOM " << i << std::endl; + return 1; + } + char data[max_test_file_size]; + f.read(data, file_data[i][0]); + if (!f.good()) { + std::cout << "Unable to read data " << i << std::endl; + return 1; + } + + if (memcmp(data, file_data[i] + 1, file_data[i][0]) != 0) { + std::cout << "Incorrect read data " << i << std::endl; + return 1; + } + } + + return 0; +} + int testFStream(int, char* []) { int ret = 0; ret |= testNoFile(); ret |= testBOM(); + ret |= testBOMIO(); return ret; } diff --git a/Utilities/KWSys/vtksys/testHashSTL.cxx b/Utilities/KWSys/vtksys/testHashSTL.cxx deleted file mode 100644 index 18cae7ff8..000000000 --- a/Utilities/KWSys/vtksys/testHashSTL.cxx +++ /dev/null @@ -1,64 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#include "kwsysPrivate.h" -#include KWSYS_HEADER(hash_map.hxx) -#include KWSYS_HEADER(hash_set.hxx) - -// Work-around CMake dependency scanning limitation. This must -// duplicate the above list of headers. -#if 0 -# include "hash_map.hxx.in" -# include "hash_set.hxx.in" -#endif - -#include - -#if defined(_MSC_VER) -# pragma warning(disable : 4786) -#endif - -#if defined(__sgi) && !defined(__GNUC__) -# pragma set woff 1468 /* inline function cannot be explicitly instantiated \ - */ -#endif - -template class kwsys::hash_map; -template class kwsys::hash_set; - -static bool test_hash_map() -{ - using mtype = kwsys::hash_map; - mtype m; - const char* keys[] = { "hello", "world" }; - m[keys[0]] = 1; - m.insert(mtype::value_type(keys[1], 2)); - int sum = 0; - for (auto& mi : m) { - std::cout << "Found entry [" << mi.first << "," << mi.second << "]" - << std::endl; - sum += mi.second; - } - return sum == 3; -} - -static bool test_hash_set() -{ - using stype = kwsys::hash_set; - stype s; - s.insert(1); - s.insert(2); - int sum = 0; - for (int si : s) { - std::cout << "Found entry [" << si << "]" << std::endl; - sum += si; - } - return sum == 3; -} - -int testHashSTL(int, char* []) -{ - bool result = true; - result = test_hash_map() && result; - result = test_hash_set() && result; - return result ? 0 : 1; -} diff --git a/Utilities/KWSys/vtksys/testProcess.c b/Utilities/KWSys/vtksys/testProcess.c index 39aaa23ba..eed770cd8 100644 --- a/Utilities/KWSys/vtksys/testProcess.c +++ b/Utilities/KWSys/vtksys/testProcess.c @@ -24,10 +24,6 @@ # include #endif -#if defined(__BORLANDC__) -# pragma warn - 8060 /* possibly incorrect assignment */ -#endif - /* Platform-specific sleep functions. */ #if defined(__BEOS__) && !defined(__ZETA__) @@ -454,24 +450,25 @@ static int runChild2(kwsysProcess* kp, const char* cmd[], int state, printf("The process is still executing.\n"); break; case kwsysProcess_State_Expired: - printf("Child was killed when timeout expired.\n"); + printf("Subprocess was killed when timeout expired.\n"); break; case kwsysProcess_State_Exited: - printf("Child exited with value = %d\n", kwsysProcess_GetExitValue(kp)); + printf("Subprocess exited with value = %d\n", + kwsysProcess_GetExitValue(kp)); result = ((exception != kwsysProcess_GetExitException(kp)) || (value != kwsysProcess_GetExitValue(kp))); break; case kwsysProcess_State_Killed: - printf("Child was killed by parent.\n"); + printf("Subprocess was killed by parent.\n"); break; case kwsysProcess_State_Exception: - printf("Child terminated abnormally: %s\n", + printf("Subprocess terminated abnormally: %s\n", kwsysProcess_GetExceptionString(kp)); result = ((exception != kwsysProcess_GetExitException(kp)) || (value != kwsysProcess_GetExitValue(kp))); break; case kwsysProcess_State_Disowned: - printf("Child was disowned.\n"); + printf("Subprocess was disowned.\n"); break; case kwsysProcess_State_Error: printf("Error in administrating child process: [%s]\n", @@ -631,7 +628,8 @@ int main(int argc, const char* argv[]) } fprintf(stderr, "Invalid test number %d.\n", n); return 1; - } else if (n >= 1 && n <= 10) { + } + if (n >= 1 && n <= 10) { /* This is the parent process for a requested test number. */ int states[10] = { kwsysProcess_State_Exited, kwsysProcess_State_Exited, @@ -709,7 +707,8 @@ int main(int argc, const char* argv[]) free(argv0); #endif return r; - } else if (argc > 2 && strcmp(argv[1], "0") == 0) { + } + if (argc > 2 && strcmp(argv[1], "0") == 0) { /* This is the special debugging test to run a given command line. */ const char** cmd = argv + 2; @@ -720,9 +719,8 @@ int main(int argc, const char* argv[]) int r = runChild(cmd, state, exception, value, 0, 1, 0, timeout, 0, 1, 0, 0, 0); return r; - } else { - /* Improper usage. */ - fprintf(stdout, "Usage: %s \n", argv[0]); - return 1; } + /* Improper usage. */ + fprintf(stdout, "Usage: %s \n", argv[0]); + return 1; } diff --git a/Utilities/KWSys/vtksys/testSystemInformation.cxx b/Utilities/KWSys/vtksys/testSystemInformation.cxx index 154517eae..4f0c522e4 100644 --- a/Utilities/KWSys/vtksys/testSystemInformation.cxx +++ b/Utilities/KWSys/vtksys/testSystemInformation.cxx @@ -11,29 +11,13 @@ #include -#if defined(KWSYS_USE_LONG_LONG) -# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG) -# define iostreamLongLong(x) (x) -# else -# define iostreamLongLong(x) ((long)x) -# endif -#elif defined(KWSYS_USE___INT64) -# if defined(KWSYS_IOS_HAS_OSTREAM___INT64) -# define iostreamLongLong(x) (x) -# else -# define iostreamLongLong(x) ((long)x) -# endif -#else -# error "No Long Long" -#endif - #define printMethod(info, m) std::cout << #m << ": " << info.m() << "\n" #define printMethod2(info, m, unit) \ std::cout << #m << ": " << info.m() << " " << unit << "\n" #define printMethod3(info, m, unit) \ - std::cout << #m << ": " << iostreamLongLong(info.m) << " " << unit << "\n" + std::cout << #m << ": " << info.m << " " << unit << "\n" int testSystemInformation(int, char* []) { diff --git a/Utilities/KWSys/vtksys/testSystemTools.cxx b/Utilities/KWSys/vtksys/testSystemTools.cxx index 670e8dc8b..cfa420df4 100644 --- a/Utilities/KWSys/vtksys/testSystemTools.cxx +++ b/Utilities/KWSys/vtksys/testSystemTools.cxx @@ -20,18 +20,18 @@ // left on disk. #include +#include /* free */ +#include /* strcmp */ #include #include -#include /* free */ -#include /* strcmp */ #if defined(_WIN32) && !defined(__CYGWIN__) -# include /* _umask (MSVC) / umask (Borland) */ +# include /* _umask (MSVC) */ # ifdef _MSC_VER -# define umask _umask // Note this is still umask on Borland +# define umask _umask # endif #endif #include /* umask (POSIX), _S_I* constants (Windows) */ -// Visual C++ does not define mode_t (note that Borland does, however). +// Visual C++ does not define mode_t. #if defined(_MSC_VER) typedef unsigned short mode_t; #endif @@ -328,7 +328,14 @@ static bool CheckFileOperations() } // While we're at it, check proper TestFileAccess functionality. - if (kwsys::SystemTools::TestFileAccess(testNewFile, + bool do_write_test = true; +#if defined(__linux__) + // If we are running as root on linux ignore this check, as + // root can always write to files + do_write_test = (getuid() != 0); +#endif + if (do_write_test && + kwsys::SystemTools::TestFileAccess(testNewFile, kwsys::TEST_FILE_WRITE)) { std::cerr << "TestFileAccess incorrectly indicated that this is a writable file:" @@ -415,6 +422,28 @@ static bool CheckFileOperations() res = false; } +#if !defined(_WIN32) + std::string const testBadSymlink(testNewDir + "/badSymlink.txt"); + std::string const testBadSymlinkTgt(testNewDir + "/missing/symlinkTgt.txt"); + if (!kwsys::SystemTools::CreateSymlink(testBadSymlinkTgt, testBadSymlink)) { + std::cerr << "Problem with CreateSymlink for: " << testBadSymlink << " -> " + << testBadSymlinkTgt << std::endl; + res = false; + } + + if (!kwsys::SystemTools::Touch(testBadSymlink, false)) { + std::cerr << "Problem with Touch (no create) for: " << testBadSymlink + << std::endl; + res = false; + } +#endif + + if (!kwsys::SystemTools::Touch(testNewDir, false)) { + std::cerr << "Problem with Touch (no create) for: " << testNewDir + << std::endl; + res = false; + } + kwsys::SystemTools::Touch(testNewFile, true); if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) { std::cerr << "Problem with RemoveADirectory for: " << testNewDir @@ -500,7 +529,7 @@ static bool CheckStringOperations() char* cres = kwsys::SystemTools::AppendStrings("Mary Had A", " Little Lamb."); - if (strcmp(cres, "Mary Had A Little Lamb.")) { + if (strcmp(cres, "Mary Had A Little Lamb.") != 0) { std::cerr << "Problem with AppendStrings " << "\"Mary Had A\" \" Little Lamb.\"" << std::endl; res = false; @@ -508,7 +537,7 @@ static bool CheckStringOperations() delete[] cres; cres = kwsys::SystemTools::AppendStrings("Mary Had", " A ", "Little Lamb."); - if (strcmp(cres, "Mary Had A Little Lamb.")) { + if (strcmp(cres, "Mary Had A Little Lamb.") != 0) { std::cerr << "Problem with AppendStrings " << "\"Mary Had\" \" A \" \"Little Lamb.\"" << std::endl; res = false; @@ -522,7 +551,7 @@ static bool CheckStringOperations() } cres = kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.", "aeiou"); - if (strcmp(cres, "Mry Hd A Lttl Lmb.")) { + if (strcmp(cres, "Mry Hd A Lttl Lmb.") != 0) { std::cerr << "Problem with RemoveChars " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; @@ -530,7 +559,7 @@ static bool CheckStringOperations() delete[] cres; cres = kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb."); - if (strcmp(cres, "A")) { + if (strcmp(cres, "A") != 0) { std::cerr << "Problem with RemoveCharsButUpperHex " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; @@ -539,7 +568,7 @@ static bool CheckStringOperations() char* cres2 = strdup("Mary Had A Little Lamb."); kwsys::SystemTools::ReplaceChars(cres2, "aeiou", 'X'); - if (strcmp(cres2, "MXry HXd A LXttlX LXmb.")) { + if (strcmp(cres2, "MXry HXd A LXttlX LXmb.") != 0) { std::cerr << "Problem with ReplaceChars " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; @@ -561,7 +590,7 @@ static bool CheckStringOperations() } cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb."); - if (strcmp(cres, "Mary Had A Little Lamb.")) { + if (strcmp(cres, "Mary Had A Little Lamb.") != 0) { std::cerr << "Problem with DuplicateString " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; @@ -1113,6 +1142,42 @@ static bool CheckURLParsing() return ret; } +static bool CheckSplitString() +{ + bool ret = true; + + auto check_split = [](std::string const& input, + std::initializer_list expected) -> bool { + auto const components = kwsys::SystemTools::SplitString(input, '/'); + if (components.size() != expected.size()) { + std::cerr << "Incorrect split count for " << input << ": " + << components.size() << std::endl; + return false; + } + size_t i = 0; + for (auto& part : expected) { + if (components[i] != part) { + std::cerr << "Incorrect split component " << i << " for " << input + << ": " << components[i] << std::endl; + return false; + } + ++i; + } + return true; + }; + + // No separators + ret &= check_split("nosep", { "nosep" }); + // Simple + ret &= check_split("first/second", { "first", "second" }); + // Separator at beginning + ret &= check_split("/starts/sep", { "", "starts", "sep" }); + // Separator at end + ret &= check_split("ends/sep/", { "ends", "sep", "" }); + + return ret; +} + int testSystemTools(int, char* []) { bool res = true; @@ -1162,5 +1227,7 @@ int testSystemTools(int, char* []) res &= CheckURLParsing(); + res &= CheckSplitString(); + return res ? 0 : 1; } diff --git a/Utilities/MPI/CMakeLists.txt b/Utilities/MPI/CMakeLists.txt index cca9408b1..2170a6119 100644 --- a/Utilities/MPI/CMakeLists.txt +++ b/Utilities/MPI/CMakeLists.txt @@ -14,6 +14,7 @@ vtk_module_definitions(VTK::mpi INTERFACE MPICH_SKIP_MPICXX OMPI_SKIP_MPICXX + MPI_NO_CPPBIND _MPICC_H) if (APPLE AND TARGET MPI::MPI_C) diff --git a/Utilities/MPI/vtk_mpi.h b/Utilities/MPI/vtk_mpi.h index ef2baa4d2..ea6a9e924 100644 --- a/Utilities/MPI/vtk_mpi.h +++ b/Utilities/MPI/vtk_mpi.h @@ -16,6 +16,12 @@ #define _vtk_mpi_ibm #endif +// Skip SGI MPT's C++ support. +#ifndef MPI_NO_CPPBIND +#define MPI_NO_CPPBIND +#define _vtk_mpi_sgi +#endif + // Include the MPI header. #include @@ -34,3 +40,8 @@ #undef _MPICC_H #undef _vtk_mpi_ibm #endif + +#ifdef _vtk_mpi_sgi +#undef MPI_NO_CPPBIND +#undef _vtk_mpi_sgi +#endif diff --git a/Utilities/Maintenance/SourceTarball.bash b/Utilities/Maintenance/SourceTarball.bash index ff8fe0655..15e3ebdaf 100755 --- a/Utilities/Maintenance/SourceTarball.bash +++ b/Utilities/Maintenance/SourceTarball.bash @@ -106,7 +106,7 @@ download () { for urlbase in $urlbases; do url="$( echo "$urlbase" | sed -e "s/ALGO/$algo/;s/HASH/$hash/" )" - if wget "$url" -O "$temppath" >&2; then + if wget --no-verbose "$url" -O "$temppath" >&2; then mv "$temppath" "$path" return else diff --git a/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx b/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx index f9d7edd93..60195d8e9 100644 --- a/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx +++ b/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx @@ -248,11 +248,16 @@ bool vtkPythonInterpreter::Initialize(int initsigs /*=0*/) PySys_SetArgvEx(0, nullptr, 0); #ifdef VTK_PYTHON_FULL_THREADSAFE +#if PY_VERSION_HEX < 0x03090000 + // In Python 3.9 and higher, PyEval_ThreadsInitialized() and + // PyEval_InitThreads() are deprecated and do nothing. + // GIL initialization is handled by Py_InitializeEx(). int threadInit = PyEval_ThreadsInitialized(); if (!threadInit) { PyEval_InitThreads(); // initialize and acquire GIL } +#endif // Always release GIL, as it has been acquired either by PyEval_InitThreads // prior to Python 3.7 or by Py_InitializeEx in Python 3.7 and after PyEval_SaveThread(); diff --git a/Wrapping/Python/vtkmodules/util/numpy_support.py b/Wrapping/Python/vtkmodules/util/numpy_support.py index 5824ef391..5bf475f23 100644 --- a/Wrapping/Python/vtkmodules/util/numpy_support.py +++ b/Wrapping/Python/vtkmodules/util/numpy_support.py @@ -49,8 +49,7 @@ elif VTK_LONG_TYPE_SIZE == 8: def get_vtk_array_type(numpy_array_type): """Returns a VTK typecode given a numpy array.""" # This is a Mapping from numpy array types to VTK array types. - _np_vtk = {numpy.character:vtkConstants.VTK_UNSIGNED_CHAR, - numpy.uint8:vtkConstants.VTK_UNSIGNED_CHAR, + _np_vtk = {numpy.uint8:vtkConstants.VTK_UNSIGNED_CHAR, numpy.uint16:vtkConstants.VTK_UNSIGNED_SHORT, numpy.uint32:vtkConstants.VTK_UNSIGNED_INT, numpy.uint64:vtkConstants.VTK_UNSIGNED_LONG_LONG, diff --git a/Wrapping/PythonCore/PyVTKMethodDescriptor.cxx b/Wrapping/PythonCore/PyVTKMethodDescriptor.cxx index 10b78e92f..2c7e05cc0 100644 --- a/Wrapping/PythonCore/PyVTKMethodDescriptor.cxx +++ b/Wrapping/PythonCore/PyVTKMethodDescriptor.cxx @@ -95,7 +95,7 @@ static PyObject* PyVTKMethodDescriptor_Call(PyObject* ob, PyObject* args, PyObje if (func) { - result = PyEval_CallObjectWithKeywords(func, args, kwds); + result = PyObject_Call(func, args, kwds); Py_DECREF(func); } diff --git a/Wrapping/PythonCore/vtkPythonCommand.cxx b/Wrapping/PythonCore/vtkPythonCommand.cxx index e03cce2ea..863920322 100644 --- a/Wrapping/PythonCore/vtkPythonCommand.cxx +++ b/Wrapping/PythonCore/vtkPythonCommand.cxx @@ -234,7 +234,7 @@ void vtkPythonCommand::Execute(vtkObject* ptr, unsigned long eventtype, void* ca arglist = Py_BuildValue("(Ns)", obj2, eventname); } - PyObject* result = PyEval_CallObject(this->obj, arglist); + PyObject* result = PyObject_Call(this->obj, arglist, nullptr); Py_DECREF(arglist); if (result) diff --git a/Wrapping/PythonCore/vtkPythonUtil.cxx b/Wrapping/PythonCore/vtkPythonUtil.cxx index 8a2a9b284..fc6a04b5f 100644 --- a/Wrapping/PythonCore/vtkPythonUtil.cxx +++ b/Wrapping/PythonCore/vtkPythonUtil.cxx @@ -564,7 +564,7 @@ vtkObjectBase* vtkPythonUtil::GetPointerFromObject(PyObject* obj, const char* re if (obj) { PyObject* arglist = Py_BuildValue("()"); - PyObject* result = PyEval_CallObject(obj, arglist); + PyObject* result = PyObject_Call(obj, arglist, nullptr); Py_DECREF(arglist); Py_DECREF(obj); if (result == nullptr) @@ -1083,7 +1083,7 @@ void vtkPythonVoidFunc(void* arg) arglist = Py_BuildValue("()"); - result = PyEval_CallObject(func, arglist); + result = PyObject_Call(func, arglist, nullptr); Py_DECREF(arglist); if (result) -- 2.30.2